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.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?

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 (192.168.0.2) 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?