Advertisement

Winsock problem...

Started by October 15, 2000 07:50 PM
14 comments, last by Yanroy 24Β years, 3Β months ago
*last gasp attempt at getting an answer*

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


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

You''re server code, as it stands, won''t work. In fact, my guess as to what it does any recv will almost certainly return a SOCKET_ERROR (with an error message of WSAEWOULDBLOCK) and then you''ll reset the connection.

First, in response to the other thread, DON''T turn off the Nagle algorithm. It will have no effect on your problem and is one of the big no-no''s in the winsock FAQ.

Now the reason I say your server code won''t work is that you''re specifying that it use non-blocking sockets. Basically what happens with non-blocking sockets is if you try a read and there''s no data to read, instead of waiting for some it returns SOCKET_ERROR and WSAGetLastError() will return WSAEWOULDBLOCK (which means "I would block on this socket until data is available because there''s none there right now except that this socket is in non-blocking mode so I can''t"). You cannot treat any SOCKET_ERROR condition as a failure to trigger a reset. Often a socket call returns an error condition for a successful operation. Check the documentation of each call for what errors it may return and figure out how you want to respond to them.

Also, you didn''t post the client code. Are you sre your client code is right and that it''s sending the string?
Advertisement
Reguarding Nagling...

Nagle DOES NOT block forever. The default timeout before small packets are sent along is 300 milliseconds. The quick-and-nasty explanation is that upon sending, the size of the data is checked. If it does not meet a certain threshold, it is queued and held for up to 300ms waiting for another send. If there is another send before the 300ms is up that puts the total queue length up past the threshold, all data is sent. If no more sends are issued, the data is sent at the above mentioned timeout.

Note, this only works on TCP. UDP is uneffected.
I''m just gonna point out a few things:


char *interface= NULL;
NumGateways = MaxConnections;

// set up local info
LocalInfo.sin_family = AF_INET;
LocalInfo.sin_addr.s_addr = (!interface)? INADDR_ANY:inet_addr(interface);
LocalInfo.sin_port = htons(ListenPort);

------------------------------
check your use of ''interface''
------------------------------


ListenSocket = socket(AF_INET, SOCK_STREAM, 0); // create TCP/IP Socket

------------------------------
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
------------------------------


if (Gateways.Inactive())
{
Gateways.Accept(ListenSocket);<br> if (OnConnectCallback)<br> OnConnectCallback(i);<br>}<br></code><br>β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”<br>check this section. I''m not sure where your logic for active vs. inactive is coming from.<br>β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”<br><br>And now for a little criteque? Adopt the hungarian naming convention. =) I don''t know what it is, but I can''t handle looking at code that has no simple method of determining if a variable is a global or member variable.<br><br> </i>
The client is the MSDN sample app changed so that it will send a string I type from the keyboard instead of the default every time. If you want to see the client code, look on MSDN . Sorry about not using hungarian, but it drives me crazy. I need to keep a book open to the page where it says what characters mean what, and my desk only has room for about 2 books (I need every book I can fit on the desk!).

JonStelly: Thanks for your input. I came across that protocol selector flag thingy in winsock2.h, but the example server from MSDN uses 0, so that is what I used. I will change that ASAP, however. I am afraid I don''t understand your last comment (not including the critique ). If you mean how do I tell whether or not it is inactive, the member function Inactive() returns !Active (the opposite of the member bool Active).

Thanks everyone... I will add/change the things you have mentioned so far. Because I have gone ahead and added more code to my server which isn''t finished, I can''t conduct another test right away. I may also wait until I get my MFC client working (I haven''t started yet, so I wasn''t lying about the MSDN client... that is what I was using for tests). Thanks again.

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


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.

I dunno if you care or not but I''ve made a pretty nice wrapper thats 100% open soruce for winsock api. Check it out at http://torquel.tripod.com/
- torquel

This topic is closed to new replies.

Advertisement