TCP Client Hangs ( But not in debug )

Blitz3D Forums/Blitz3D Programming/TCP Client Hangs ( But not in debug )

Gabriel(Posted 2004) [#1]
Kinda weird this one. I'm plugging away slowly at my multiplayer code and everything's coming along nicely so far. I'm testing on localhost so I have two copies of the game running in debug mode to make sure everything's good, and it seems to be fine.
If I make an exe and do the same thing, the client hangs when it tries to join the server. Now I know OpenTCPStream can cause hangs like that if there is no response, but this is quite a long hang, and I'm not entirely sure why the server doesn't respond. In debug mode it does. Now obviously the server can't have focus if the client has it, but don't B3d programs continue to run anyway?

They ought to be happy to multitask because there are delays to ensure that there is plenty of cpu time to go round. Except obviously that I can't put a delay in the middle of a call to OpenTCPStream. Is that the problem? Should i just ignore it as long as it runs ok in debug mode?


skidracer(Posted 2004) [#2]
Could just as easily be the Server hanging, you checked it's delays?


Gabriel(Posted 2004) [#3]
5 Milliseconds per frame. Everything works perfectly in debug mode. When I compile though, different story.

The Server opens just fine. Then I open another instance, the client. I hit the connect button and the client hangs completely ( to the point where Windows thinks the graphics card has failed after around 30 seconds.


skidracer(Posted 2004) [#4]
Eek.


Neochrome(Posted 2004) [#5]
try connecting with two machines in a network, i had the same problem, worked ok with two computers


Gabriel(Posted 2004) [#6]
Yeah, I don't have a network to test on, unfortunately. It did occur to me that it may only be a problem because I'm using localhost, so I guess I'll leave it for now and just keep testing in debug mode until it's all finished. Hopefully if there is a problem, it won't be any harder to solve then.


Nacra(Posted 2004) [#7]
Are client and server trying to grab the same port? That doesn't explain why debug works but not retail.

You might get a copy of Microsoft Virtual PC ($129) to run multiple windows sessions on the same box. Some people use that to learn or simulate networks. http://www.adtmag.com/article.asp?id=8606


Gabriel(Posted 2004) [#8]
Erm.. aren't client and server supposed to be using the same port? How are they going to link up if they're using a different port?

I open a TCP server on the port. Then AcceptTCPStream's on that server, while the client OpenTCPStream's to that port. As I say, in debug mode, it runs along merrily, chatting, playing the game, connecting, disconnecting, kicking, all works flawlessly.


Nacra(Posted 2004) [#9]
> Erm.. aren't client and server supposed to be using the same port?

No. The client and server sides of a TCP connection can be on different ports. For example connecting an ftp client to an ftp server: The remote server is listening on port 20 but the client will locally use some random, high port like 15443. And you could have the client and server on a single machine.

But the thought I originally had for your deal was that only one process should be listening on one port per machine. It should be exclusive access, one port, one process. If, for example, two processes are listening on port 3090, which one responds to a connection request or data transfer? I don't know your client-server interactions - is it possible that they're both trying to connect to each other over the same port?

But this theorizing doesn't explain why it works for you in debug mode. !!??


Paul