UNET NetworkTransport.AddHost - Check if port is already open

Hey everyone,

I have a question about the low level NetworkTransport interface.

I can get the server and a client to send messages to each other, but when I try to run two instances of the client the second one fails to connect, because the port is already in use by the first one.

It doesn’t throw an exception, it just logs an error message in the console saying that the port is open and I don’t know how to go about catching this error. I need a way to check if the port is already open before trying to connect to it

I could manually connect the second client to another port, but I would like to have that done automatically in case the player has that particular port open. Is that a reasonable thing to do or should I just throw them an error message?

In any case I need to know how to check if NetworkTransport.AddHost will fail and do something about it

Alright, sorry for bumping this, but I have an update in case anyone else is having the same issue :smiley:

I figured out that if AddHost fails it will set myHostID to -1 so I ended up just checking for negative values to see if it failed.

But it still throws the ‘port already occupied’ error in the console,

“Cannot open socket on ip {*} and port
{6969}; check please your network,
most probably port has been already
occupied”

which is a bit concerning, I don’t feel like having a bunch of network errors in the console is the optimal way of doing things :smiley: but at least it gets things running for the moment.

If you know any better way of going about this please tell me