Asynchronous Socket

suggest change


By using asynchronous sockets a server can listening for incoming connections and do some other logic in the mean time in contrast to synchronous socket when they are listening they block the main thread and the application is becoming unresponsive an will freeze until a client connects.


Socket and network

How to access a Server outside my own network? This is a common question and when it is asked is mostly flagged as of topic.

Server Side

On the network of your server you need to port forward your router to your server.

For Example PC where server is running on:

local IP =

Server is listening to port 1234.

Forward incoming connections on Port 1234 router to

Client Side

The only thing you need to change is the IP. You don’t want to connect to your loopback address but to the public IP from the network your server is running on. This IP you can get here.

_connectingSocket.Connect(new IPEndPoint(IPAddress.Parse(""), 1234));

So now you create a request on this endpoint : if you did property port forward your router your server and client will connect without any problem.

If you want to connect to a local IP you won’t have to portforwart just change the loopback address to or something like that.

Sending data:

Data is send in byte array. You need to pack you data into an byte array and unpack it on the other side.

If you are familiar with socket you also can try to encrypt your byte array before sending. This will prevent anyone from stealing your package.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents