Skip to main content
gamedev.net
🔒 Locked

recv problem

Started by McDanger Apr 19, 2004 at 1:02 AM 11 replies 1k views
Original Post
McDanger
McDanger
I''m writing a server application to run on a *nix machine, and the clients are coded using winsock. Everytime I send a packet from the client and the server receives it, the return value from recv is -1. Any ideas? I''ve really been staring at this one for a while... I''m thinking there''s an issue here I''m not aware of. Thanks for your time
Nervo
Nervo
There is obviously an error occuring, but its hard to say unless you post a snippet from both your client and server code within the area that the issue occurs.
Well, R2D22U2..
Peon
Peon
I''d say post some code too... can you send a packet the other way (server->client)?
Peon
Nervo
Nervo
quote:
Original post by Anonymous Poster
When recv() fails, call GetLastError() and look up the error code in MSDN. If the error code doesn''t make sense, post it here along with some code.


Sounds good, except the recv call is being done on a *nix platform. If the clientside is generating an error too, then he could call GetLastError().
Well, R2D22U2..
Voxelsoft
Voxelsoft
char *wtf = strerror(errno);
Vox
McDanger
McDanger
Thanks for your prompt replies everybody

--I printed errno, here's what it's giving me:

Bad address

Does this mean I'm attempting recv on the wrong socket somehow, or what? What sorts of things can cause a bad address error?

Let me add a little more information:

I have some debugging script in there that's telling me I'm doing an recv on the same socket that's being disconnected after the -1 is returned from recv.

[edited by - McDanger on April 19, 2004 11:03:20 AM]

[edited by - McDanger on April 19, 2004 11:07:00 AM]
Anon Mike
Anon Mike
My guess is that you either didn''t bind or bound to an invalid address before calling recv.
-Mike
Pipo DeClown
Pipo DeClown
Are you sure that socket is valid? If you''re programming the server, you must pass the clientSocket, and not the listeningSocket.

--
You''re Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..
McDanger
McDanger
Figured out what was wrong.

Basically -- the buffer I was passing wasn''t initialized. Yes, a newbie mistake I was furious at myself over -- but not as furious as I was over the "Bad address" error message. I didn''t even think to check for something as stupid as not having initialized my buffer because it said "Bad address" and I instantly though my socket was messed up.

Thanks for your time trying to figure this out, guys!
hplus0603
hplus0603
The "address" in question was probably the address you passed into recv(), i e a pointer value kind of address, not a network kind of address.

Also, I recommend you start using recvfrom(). You''ll realize that you want it soon enough anyway (say, to make client/server work through NAT).
enum Bool { True, False, FileNotFound };
McDanger
McDanger
quote:
Original post by hplus0603
The "address" in question was probably the address you passed into recv(), i e a pointer value kind of address, not a network kind of address.

Also, I recommend you start using recvfrom(). You''ll realize that you want it soon enough anyway (say, to make client/server work through NAT).


I thought recvfrom was for UDP?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.