473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

System.Net.Socket.Receive(...) bug?

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.Strea m,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


Nov 17 '05 #1
1 3792
The machines where u r experieencing problem with Recieve.
Have you tried to Telnet your application?

Also can you listen on an actual IP , like 192.168.0.0 or whatever you have
on your side?

You might also want to see the differences between the two set of machines,
one where its working and one where it is not. May be verify if same version
of patches / involved software are there?

HTH
rawCoder
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
4
by: Qingdong Z. | last post by:
I have an asynchronous Server Socket to push data to client (Socket.BeginSend) when data is available, Meanwhile, the client socket use Synchronous Client Socket to receive the data. I have two...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
2
by: Rene Sørensen | last post by:
I'm using .NET 2.0 VS 2005 I'm creating a function that dos something similar to the. SmoApplication.EnumAvailableSqlServers() function. But for som resone I get an error or do i?. The problem...
0
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.