GNet Host and Client same machine

BlitzMax Forums/BlitzMax Programming/GNet Host and Client same machine

Will(Posted 2005) [#1]
I dont want to write a whole seperate host and client - I'd rather make a host on the host computer, and then make a client to join that host for the host themself. The problem is, once I call the GNetConnect(client, ip, port) I am stuck until it fails, and cannot call GNetAccept(host) in order to accept my own incoming connection! How do I do this?

Thanks, Will.


Will(Posted 2005) [#2]
This is important, so I'm bumping it.


Tibit(Posted 2005) [#3]
I'm not sure about your problem.

First, I suggest you checkout TNet: www.truplo.com/TNet
Which is a multiplayer game library for BlitzMax.

Second, or if you don't want to use TNet, you need to explain a bit more, so that we can solve your problem.

I'm not very familiar with GNet, but I do have a fair experience with TCP so I'll try to assume what's wrong:

GNet uses TCP, therefore a call to "Connect(IP,Port)" would mean you would try to establish a connection between two TCP sockets, a local to a remote listening TCP socket, which is most likley a GNetHost doing GNetAccept(). You will be "stuck" at connection when using TCP. It is the way TCP works, and as far as I know you can only work around it by using threads, which blitzmax has not. Another option would be to skip TCP and use UDP.

Please, if you want, explain more what you are doing, perhaps there is a simpler way?

It does sound like you are trying to do some TCP hole-punching for nat punch-through. Is that right? ;)


Will(Posted 2005) [#4]
The problem I've encountered is that I cannot call two commands at once. The command GNetConnect halts the program until it either connects or fails - so I can't call GNetAccept at the same time - which I need to make it connect. I need to call one command while still calling the other. I think threading sounds like the way to do this, or some more detailed GNet Connect command. Is there threading with MaxGUI?


ImaginaryHuman(Posted 2005) [#5]
Maybe if you use the GUI module for your button you could add a hook to it which runs a piece of code to send back the response signal so that it occurs when the button is pressed regardless of whatever else the rest of your code is waiting for?


Tibit(Posted 2005) [#6]
By the way, Will, why do you need to connect while you accept?

1. TCP Connect - Ask to connect to an remote ip/port
2. The remote application at that ip/port runs Accept() and therefore it accepts the connecting client.
3. TCP sends some data back N forth and we are connected.

If you want to connect to another client, use connect again, wait for response.

If you have a host, he should never use connect, that is up to the new clients to do.