S
Saso Zagoranski
Hi!
I have simple client/server game that uses sockets to transfer different
messages.
The server and the client are running on the same machine.
These are the steps:
1. start the server (I use a TcpListener on port 8080) and wait for messages
byte[] buffer = new byte[4096];
listener = new TcpListener(IPAddress.Parse("127.0.0.1"),8080);
Socket client = listener.AcceptSocket(); // wait for a connection
int size = client.Receive(buffer); // wait for the first message during
client/server initialization
After the first messages is successfully received I send a response to the
client with his new ID and then
this socket is put on another thread.
2. The client side:
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
mainSocket = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
mainSocket.Connect(new IPEndPoint(ipAddress,8080));
mainSocket.Send( buffer ); // the client sends the request
mainSocket.Receive(buffer ); // and waits for a response
The problem is that the above code works on some machines and doesn't on
others.
The problem is in the Receive method. Here is what happens:
1.. I start the server
2.. I connect with the client
3.. The server awaits data (the receive method waits)
4.. I send a request from the client
5.. the server DOESN'T GET THE DATA!
6.. So the Receive method on the server waits
7.. and because the client expects a response it also hangs in the Receive
method
Netstats shows that there is a connection on port 8080 (I've also tried
other ports).
I've tested 5 machines... It works only on 2. I've turned off firewalls.
These
are all Windows XP SP2 machines... On the 2 that the thing worked I've also
tried communicating over the internet, where the server was somewhere else
and it worked! On the other 3 it doesn't even work locally...
I've even tried sending 5 requests from the client (mainSocket.Send(buffer)
x 5) and that
didn't work either.
Is there something wrong with the receive method or am I doing something
wrong?!
PLEASE HELP!
thanks,
saso
I have simple client/server game that uses sockets to transfer different
messages.
The server and the client are running on the same machine.
These are the steps:
1. start the server (I use a TcpListener on port 8080) and wait for messages
byte[] buffer = new byte[4096];
listener = new TcpListener(IPAddress.Parse("127.0.0.1"),8080);
Socket client = listener.AcceptSocket(); // wait for a connection
int size = client.Receive(buffer); // wait for the first message during
client/server initialization
After the first messages is successfully received I send a response to the
client with his new ID and then
this socket is put on another thread.
2. The client side:
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
mainSocket = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
mainSocket.Connect(new IPEndPoint(ipAddress,8080));
mainSocket.Send( buffer ); // the client sends the request
mainSocket.Receive(buffer ); // and waits for a response
The problem is that the above code works on some machines and doesn't on
others.
The problem is in the Receive method. Here is what happens:
1.. I start the server
2.. I connect with the client
3.. The server awaits data (the receive method waits)
4.. I send a request from the client
5.. the server DOESN'T GET THE DATA!

6.. So the Receive method on the server waits
7.. and because the client expects a response it also hangs in the Receive
method
Netstats shows that there is a connection on port 8080 (I've also tried
other ports).
I've tested 5 machines... It works only on 2. I've turned off firewalls.
These
are all Windows XP SP2 machines... On the 2 that the thing worked I've also
tried communicating over the internet, where the server was somewhere else
and it worked! On the other 3 it doesn't even work locally...
I've even tried sending 5 requests from the client (mainSocket.Send(buffer)
x 5) and that
didn't work either.
Is there something wrong with the receive method or am I doing something
wrong?!
PLEASE HELP!
thanks,
saso