• Stars
    star
    157
  • Rank 237,455 (Top 5 %)
  • Language
    C#
  • License
    Other
  • Created almost 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast, lightweight, and easy to use socket library for C#.

AwesomeSockets

Build status    NuGet version

What is AwesomeSockets?

AwesomeSockets is a C# library that facilitates network communication. It fully supports both synchronous and asynchronous communication. Callbacks for asynchronous calls can be provided as either a delegate or as a lambda.

Documentation

Using AwesomeSockets is very easy! There are two main object types, the Buffer and the Socket. The Buffer is a vehicle to hold the data, and the Socket is responsible for sending/receiving the data. All the major public methods are static, meaning you call them on the class like so:

Buffer inBuf = Buffer.new();

In order to send a message, you must first connect to them:

//Server-side code
ISocket listenSocket = AweSock.TcpListen(14804);
ISocket client = AweSock.TcpAccept(listenSocket);

//Client-side code
ISocket server = AweSock.TcpConnect(1.2.3.4, 14804);

Once you've connected, you need to construct and populate at least two Buffer objects; one for receiving and one for sending:

Buffer inBuf = Buffer.New();
Buffer outBuf = Buffer.New();

//Lets send some data to the server! Make a Buffer object and populate it with some data like so:
Buffer.ClearBuffer(outBuf);
Buffer.Add(outBuf, 42);
Buffer.Add(outBuf, "Is the ultimate answer");
Buffer.Add(outBuf, 'N');
Buffer.FinalizeBuffer(outBuf);

//Now lets send it to the server!
int bytesSent = AweSock.SendMessage(server, outBuf);

//And receive any inbound messages as well. Received datga will be stored in inBuf. 
Tuple<int, EndPoint> received = AweSock.ReceiveMessage(server, inBuf);

And thats it! The TcpAccept method will block until a connection comes in and returns the the connected Socket. If you want to have it non-blocking, we support that as well:

//Non-blocking mode returns null
AweSock.TcpAccept("", 12, SocketCommunicationTypes.NonBlocking, (listenSocket, error) => { return null; });

As you can see, we provided the NonBlocking constant and a lambda as a callback when the connection is accepted. If the listensocket parameter above is null, the error field will have an exception, indicating failure. Conversely, if the listensocket isn't null, the error will be, indicating success. This same pattern applies to TcpConnect as well.

Udp is similar, but with one major difference; the connect logic is 'reversed' for the server side. Here is an example:

//Server-side code (5.6.7.8 is the ip of the client)
ISocket client = AweSock.UdpConnect('5.6.7.8', 14804);

//Client-side code (1.2.3.4 is the ip of the server)
ISocket server = AweSock.UdpConnect('1.2.3.4', 14804);

Both ends must know the ip of the other player before hand. This is where Tcp can come in. You can establish an ephermeral Tcp socket and use the ISocket object to get each others Ip addresses. It is also worth noting, there is no ability to have blocking logic as Udp is stateless. Everything else is identical in usage to Tcp.

If you have any additional questions, shoot me an email at [email protected] or message me on github @nterry. Additional documentation will be added as XML as needed.

More Repositories

1

n64-kicad

A set of Kicad files detailing the N64 hardware
13
star
2

39DLL

39DLL originally implemented by 39ster ath the GMC.
C++
7
star
3

39DLL-4-Linux

A port of the 39dll for Linux and Android originally written for Win32 by Luke Graham (39ster in GMC)
C++
5
star
4

heroku-buildpack-csharp

Buildpack for C# on Heroku using Mono
Ruby
3
star
5

bosh_azure_cpi

BOSH CPI for Microsoft Azure
Ruby
2
star
6

PheenixSite

Main Pheenix Game Studios site
HTML
1
star
7

iron-spect

C# project file parser and inspector
Ruby
1
star
8

AS3RG

A Simple 3D RPG Game
C#
1
star
9

NMakeSharp

Builld system for C# projects with NuGet integration
1
star
10

Battleships

My Battleships program for CS1410
Java
1
star
11

DebSharp_OLD

A Debian package builder project template for Visual Studio
C#
1
star
12

Mono.Nat.Android

Mono.Nat for android
C#
1
star
13

AwesomeSockets-1

A java library to make server-socket communications easier
Java
1
star
14

bella-cam

Rack application to monitor Bella
Ruby
1
star
15

shippingdock

Just another Docker container manager, but more awesomer!
Ruby
1
star
16

Just-Some-Generic-Shooter

A super-awesome game for sexy, sexy people
C#
1
star
17

git-lfs4j

An implementation of the git lfs api written in Java supporting interchangeable backends
Java
1
star
18

foobarbaz

1
star
19

foobar

1
star
20

foo

1
star
21

filetree-indexer

Small app to index a filetree
C#
1
star
22

ShinyWrench

ShinyWrench quiz service
JavaScript
1
star
23

Hangman

CSIS 2450 Hangman program
Ruby
1
star
24

PheenixSiteSharp

PheenixStudios.com main site
JavaScript
1
star
25

archaius-github

A GitHub configuration source for Archaius
Java
1
star
26

Armorcide

Official Armorcide Unity project
C#
1
star
27

jclouds

Fixes where jclouds blows up when all regions in a given provider are unavailable
Java
1
star
28

Type2Byte

A class for converting managed base types to byte arrays and vice versa
C#
1
star
29

NancyDemo

A simple, self-hosted NancyFx application skeleton
C#
1
star
30

Mono.DataConverter

Full DataConverter class from Mono
1
star
31

cf-mono-buildpack

Mono buildpack for CloudFoundry.com
Ruby
1
star
32

PipeWrench

Drano for your clogged intertubes
C#
1
star
33

CROWBAR-Frontend-Node

Simple Node frontend for CROWBAR
JavaScript
1
star
34

DebSharp

A Debian package builder project template for Visual Studio
C#
1
star
35

SockLibNG

****SockLibNG has been deprecated and is now AwesomeSockets****
C#
1
star
36

SharpHTTPU

A simple HTTPU client for C#
C#
1
star
37

Unnamed3DPlatformer

An as-of-yet unnamed 3D platformer
C#
1
star
38

dynamo-jdbc

A native-protocol all-Java JDBC driver for AWS DynamoDB
1
star