Game Development Reference
In-Depth Information
Firstly, we declare a
TcpSocket
, which is connected by the next part (no matter if that's
the host or the connecting client). Then we ask the player to write a line of code. If that is
the word
host
then we wait for a connection and, when we get one, the resulting socket is
initialized from the listener. On the other hand, if the player types something else (we are
expecting an
IP address
), then we try to use that (even if it's not an IP address) to connect
to a waiting host. If that fails for any reason, we exit the application, since there is nothing
else that we can do.
At the end, we will either have a valid and connected
TcpSocket
or the application
would exit, because of an error. Once we have a connection going we can initialize the
scene: