Advertisement

Winsock problem...

Started by October 15, 2000 07:50 PM
14 comments, last by Yanroy 24 years, 3 months ago
I have a simple server and client setup. The client is a slightly modified version of the sample on MSDN, and the server is entirely mine. Here is the problem: the client connects (which is verified by the server) and then sends a string (and says it is sent OK). The server never gets the string! At first I had it do a blocking recv()... it never returned . Then I did a non-blocking recv() which returned the SOMETHINGWOULDBLOCK error (I forget the whole thing). Then I tried to check if there was data using select(). I am 99% positive I set up the select() correctly, and that keeps kicking my socket out of the fd_set structure... apparently there isn''t any data coming in. Any ideas would be extemely helpful. The server works by having an array of socket wrapper classes and a seperate thread that looks for an incoming connection, finds an empty socket and accept()s it. That part works like clockwork. The data never seems to be sent... --------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Are you using to seperate apps for the client & server, or are they the same app? If they are the same app, do you have a seperate thread for the client socket, and another for the recv socket?

If you are using a streamed socket, make sure to flush; the packets are not sent right away.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
The client and server are two separate apps on two different computers on my network. I am using a streamed socket. How do I flush the socket? I haven''t found that mentioned in my extensive search of MSDN (I think I have about half of the whole CD printed out by now )

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

I haven''t looked at the MSDN samples lately, but I''m assuming it''s something like a telnet client? On the Server, if you''re using a port that is already in use (ie 80 on a web server), perhaps the client is connecting to the web server instead of your app.

If you substitute the MSDN server for yours, does it work then?
Yes, the client works with the MSDN server. I got a fairly large chunk of my server code (converted from C to C++) directly from the MSDN example. As I said, it reports a successful connection, but no data is sent. The idea of flushing the buffer sounds reasonable, but I can''t find any info on it. I am also sure I am not connecting to the net because a: I am not logged on and b: I am connecting to "speedster" instead of an IP. Speedster is the computer the server program is running on. When I use that comp''s IP, it shows "Connected to SPEEDSTER", just like when I use the name. If anyone knows how to flush a socket stream, please post a reply. Thanks for the help so far.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

I found a define in winsock2.h that is called TCP_NODELAY. Does that make data transmit immediately? How would I use it if it did? Please help..................

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Advertisement
Show us the code where the server accept()s a new connection, and the client connect()s.
I don''t have access to the code right now (I''m at school) but I need to keep this thread alive until I can post it. Expect it by 10:00pm EST. There is a chance I won''t get to it today, but I think I will.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

TCP_NODELAY turns Nagles Algorithm off.

What nagles algorithm does is basically send data only when a certain amount is reached, thereby saving bandwidth.

It migth be the cause of you server not receiving any data but I doubt it.

Try sending a large quantity of strings and see if it makes any difference.

Heres the code to turn Nagles Algorithm off:

int iVal = 0;

if(setsockopt(m_Socket, IPPROTO_TCP, TCP_NODELAY, (char*) &iVal, sizeof(iVal)) == SOCKET_ERROR)
{
//Something wrong happened
}



Edited by - Lobo on October 17, 2000 6:01:49 PM
Thanks... I will look into that. As of the time of this post, you can find the code for gateway.dll here. I plan to add another paramter to the callback function so it is passed the IP of the new connection, allowing IP banning. That is the only change I can forsee, if no one finds any earth-shattering bugs. I know it is bad programming practice to put my class in the .cpp file, but it made things much easier and the app that uses the DLL never sees it anyway. The file looks a lot better if you download it and then view it with your IDE.

PS - The link was bad, I fixed it. It should work.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

Edited by - Yanroy on October 17, 2000 9:28:52 PM

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

This topic is closed to new replies.

Advertisement