Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/tallesl/net-socket
- Owner: tallesl
- Created: 2015-01-12T12:39:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-06T15:15:44.000Z (almost 8 years ago)
- Last Synced: 2024-10-12T15:03:00.504Z (3 months ago)
- Topics: csharp, dot-net, ipv4, network, nuget, socket, stream, tcp, wrapper
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 19
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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)
}
```