[SDL] problem with using socket from SDL_Net SDLNet_TCP_Accept
Ryan C. Gordon
icculus at icculus.org
Thu Mar 1 13:27:15 PST 2007
> anyways, what the program was meant to do is to communicate with itself.
> at start , port is random number and the IP address is localhost. so the
> computer talks to itself, at the start it sends a message which is "0" ,
> and then the program tries to recieve a message which was sent - and it
> indeed recieves, but when i get the socket of the sender (which is the
> localhost) and i try to send it a message - the message never arrives,
> so "second message recieved" text is never being shown and the program
> is in an infinite loop. please tell me what is the problem because im
> stuck for a week already..
Don't call SDLNet_TCP_Accept() a second time...you are sending on the
first socket still, but the reading portion of your code throws it away
(without closing it) and waits for a second connection, instead of
reading from the first again.
There are other bugs in the program, but if you get rid of the second
Accept and keep using the original somecomputer value, it gets to the
scanf("%s") call.
--ryan.
More information about the SDL
mailing list