A minimalist wrapper around a .NET's Stream IPv4 TCP Socket. Everything is synchronous.
Disclaimer: I've used this library only on prototypes and small use cases, it never reached production. Even though the code is fairly small, consider that while using it.
An stupid echo server:
using (var listener = new SocketListener(1337)) // Start listening
{
for (;;)
{
using (var remote = listener.Accept()) // Accepts a connection (blocks execution)
{
var data = remote.Receive(); // Receives data (blocks execution)
remote.Send(data); // Sends the received data back
}
}
}
And its client:
using (var socket = new ConnectedSocket("127.0.0.1", 1337)) // Connects to 127.0.0.1 on port 1337
{
socket.Send("Hello world!"); // Sends some data
var data = socket.Receive(); // Receives some data back (blocks execution)
}