Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tallesl/net-socket

A minimalist wrapper around System.Net.Sockets.Socket.
https://github.com/tallesl/net-socket

csharp dot-net ipv4 network nuget socket stream tcp wrapper

Last synced: 3 months ago
JSON representation

A minimalist wrapper around System.Net.Sockets.Socket.

Awesome Lists containing this project

README

        



logo

# Socket

[![][build-img]][build]
[![][nuget-img]][nuget]

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.

[build]: https://ci.appveyor.com/project/TallesL/net-socket
[build-img]: https://ci.appveyor.com/api/projects/status/github/tallesl/net-socket?svg=true
[nuget]: https://www.nuget.org/packages/Socket
[nuget-img]: https://badge.fury.io/nu/Socket.svg
[Stream]: http://msdn.microsoft.com/library/System.Net.Sockets.AddressFamily
[IPv4]: http://msdn.microsoft.com/library/System.Net.Sockets.SocketType
[TCP]: http://msdn.microsoft.com/library/System.Net.Sockets.ProtocolType
[Socket]: http://msdn.microsoft.com/library/System.Net.Sockets.Socket

## Usage

An stupid echo server:

```cs
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:

```cs
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)
}
```