I'm trying to set up my WIFI shield to send and receive messages over TCP sockets. There's a Max MSP patch as well with a TCP client object that seems to work well. Yet I cannot get the two, the WIFI shield and Max to talk to each other over TCP. What confuses me is that which IP address should I provide in the Arduino code? The router's, the shield's or the localhost IP?
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <SPI.h>
char ssid[] = "nwtwork";
//password of your WPA Network
char pass[] = "password";
WiFiClient client;
IPAddress server(); //shield IP address
void setup()
{
Serial.begin(9600);
Serial.println("** Scan Networks **");
byte numSsid = WiFi.scanNetworks();
Serial.print("SSID List:");
Serial.println(numSsid);
WiFi.begin(ssid, pass);
//delay(5000);
Serial.println("Connected to wifi");
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("Shield IP Address: ");
Serial.println(ip);
client.connect(server,7120);
if(client.connected()){
Serial.println("CLIENT AVAILABLE");
}
else {
Serial.println("CLIENT NOT AVAILABLE");
}
}
void loop () {
client.write("test");
delay(1000);
int in = client.read();
Serial.println(in);
}
Also, do the port number on both sides have to match?