WIFI shield TCP connection problem

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.println("** Scan Networks **");
  byte numSsid = WiFi.scanNetworks();
  Serial.print("SSID List:");
  WiFi.begin(ssid, pass);
  Serial.println("Connected to wifi");
  Serial.print("SSID: ");
  IPAddress ip = WiFi.localIP();
  Serial.print("Shield IP Address: ");
    Serial.println("CLIENT AVAILABLE");
  else {
    Serial.println("CLIENT NOT AVAILABLE");

void loop () {
  int in = client.read();

Also, do the port number on both sides have to match?

This is probably not going to work. If the WiFi shield is the client, the variable server should be set to the localnet ip of the other unit (MAX MSP?). Something like this:

IPAddress server( 192,168,0,2); //MAX MSP IP address

The ports do not need to match, and normally do not. Insure your wireless settings in the router allow clients access to other localnet clients. This is "default-forwarding=yes" in my router.

THanks! I've tried the local IP address ( and different ports yet I still cannot see the two connecting. The Max patch is a client too, could that be the problem?

If you want to use TCP, then one must be a server. Even UDP requires one to be a "server" (listen for UDP packets.

Thanks very much, I managed to setup a server on the Arduino. I can broadcast messages however when the Max patch sends integers (formatted like this: send "23" ), they appear as random set of characters on the server side. How are TCP messages formatted?