473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Net.Sock et.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(IPA ddress.Parse("1 27.0.0.1"),8080 );

Socket client = listener.Accept Socket(); // 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(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);

mainSocket.Conn ect(new IPEndPoint(ipAd dress,8080));

mainSocket.Send ( buffer ); // the client sends the request

mainSocket.Rece ive(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.Sen d(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 3820
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
3680
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 tried this I don't see any diffents, I am sending 10Mb and the Send/BeginSend command doesn't wait till the data is on the remotepoint. Can...
6
4096
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: Connect Receive response Send Connect ACK
4
2728
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 questions on this 1. When client socket does not receive data as fast as server, does server socket queues all the data, or just waits? If it queues,...
5
11668
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 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine...
2
4142
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 I get the last chunk of data and am not able to retrieve it anymore cause the socket will be dead. Loop: { socket.Receive <----------- data...
3
11571
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 was forcibly closed by the remote host at System.Net.Sockets.Socket.ReceiveFrom(Byte buffer, Int32 offset, Int32 s
2
15308
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 now see the socket.RecieveTimeout 'property' in the visual studio 2005 help documentation (framework 2.0) and it has example of it being used with...
2
5683
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 is that the program just return from the function when it reach the recive part( reviced = socket.Receive(bytBuffer); ), below here you can se the...
0
1563
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 socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.