July 2017
Beginner to intermediate
390 pages
10h 53m
English
It is time to set up the connection. To do this, we need to check if we have a socket or not. If we do not, something is wrong and we just abort. If we do have one, we can use it to set up the connection, as follows:
private void SetupTcpConnection()
{
if (_socket != null)
return;
_socket = new StreamSocket();
var hostName = new HostName("192.168.2.13");
var socketConnectionAwaiter = _socket.ConnectAsync(hostName, "8000");
var handler = new AsyncActionCompletedHandler(SocketConnectionCompleted);
socketConnectionAwaiter.Completed = handler;
}
I set (hardcoded) the IP address of my server and the port number 8000. As you can see, the code here is slightly different than we saw on the server side, but that is the ...
Read now
Unlock full access