All Projects → RhynoVDS → Objecttransport

RhynoVDS / Objecttransport

Licence: mit
Send and Receive objects over TCP or UDP

Projects that are alternatives of or similar to Objecttransport

Hp Socket
High Performance TCP/UDP/HTTP Communication Component
Stars: ✭ 4,420 (+11233.33%)
Mutual labels:  networking, tcp, udp
Libzt
ZeroTier Sockets - Put a network stack in your app
Stars: ✭ 486 (+1146.15%)
Mutual labels:  networking, tcp, udp
Hazel Networking
Hazel Networking is a low level networking library for C# providing connection orientated, message based communication via TCP, UDP and RUDP.
Stars: ✭ 194 (+397.44%)
Mutual labels:  networking, tcp, udp
Computer Networking
Free resources for a self-taught education in Computer Networking
Stars: ✭ 201 (+415.38%)
Mutual labels:  networking, tcp, udp
Goben
goben is a golang tool to measure TCP/UDP transport layer throughput between hosts.
Stars: ✭ 391 (+902.56%)
Mutual labels:  networking, tcp, udp
Mirror
#1 Open Source Unity Networking Library
Stars: ✭ 2,905 (+7348.72%)
Mutual labels:  networking, tcp, udp
Netlink
Socket and Networking Library using msgpack.org[C++11]
Stars: ✭ 197 (+405.13%)
Mutual labels:  networking, tcp, udp
Networker
A simple to use TCP and UDP networking library for .NET. Compatible with Unity.
Stars: ✭ 408 (+946.15%)
Mutual labels:  networking, tcp, udp
Cnp3
Computer Networking : Principles, Protocols and Practice (first and second edition, third edition is being written on https://github.com/cnp3/ebook)
Stars: ✭ 471 (+1107.69%)
Mutual labels:  networking, tcp, udp
Impulse
💣 Impulse Denial-of-service ToolKit
Stars: ✭ 538 (+1279.49%)
Mutual labels:  tcp, udp
Blinksocks
A framework for building composable proxy protocol stack.
Stars: ✭ 587 (+1405.13%)
Mutual labels:  tcp, udp
Libnet
A portable framework for low-level network packet construction
Stars: ✭ 640 (+1541.03%)
Mutual labels:  tcp, udp
Leaf
A lightweight and fast proxy utility tries to include any useful features.
Stars: ✭ 530 (+1258.97%)
Mutual labels:  tcp, udp
Laminar
A simple semi-reliable UDP protocol for multiplayer games
Stars: ✭ 530 (+1258.97%)
Mutual labels:  networking, udp
Ngtcp2
ngtcp2 project is an effort to implement IETF QUIC protocol
Stars: ✭ 589 (+1410.26%)
Mutual labels:  networking, udp
Proxy admin free
Proxy是高性能全功能的http代理、https代理、socks5代理、内网穿透、内网穿透p2p、内网穿透代理、内网穿透反向代理、内网穿透服务器、Websocket代理、TCP代理、UDP代理、DNS代理、DNS加密代理,代理API认证,全能跨平台代理服务器。
Stars: ✭ 487 (+1148.72%)
Mutual labels:  tcp, udp
Bedrockframework
High performance, low level networking APIs for building custom servers and clients.
Stars: ✭ 697 (+1687.18%)
Mutual labels:  networking, tcp
Tools
C# 工具箱,提供Socket(TCP、UDP协议)、Redis、activemq、数据库访问等技术的封装实现
Stars: ✭ 34 (-12.82%)
Mutual labels:  tcp, udp
Elixir Socket
Socket wrapping for Elixir.
Stars: ✭ 642 (+1546.15%)
Mutual labels:  tcp, udp
Parallec
Fast Parallel Async HTTP/SSH/TCP/UDP/Ping Client Java Library. Aggregate 100,000 APIs & send anywhere in 20 lines of code. Ping/HTTP Calls 8000 servers in 12 seconds. (Akka) www.parallec.io
Stars: ✭ 777 (+1892.31%)
Mutual labels:  tcp, udp

ObjectTransport

A lightweight library that allows you to send and receive objects over TCP or UDP. ObjectTranport aims to be a network framework that is as simple and lightweight as possible.

Multiple serialization options are available such as Protobuf. Serialization is injectable and you can implement your own.

Install

ObjectTransport is split into seperate packages based off your needs and available on nuget. Plese see installation instructions for more details: https://github.com/RhynoVDS/ObjectTransport/wiki/Installation

Simple Example

Starting the server

You can start a TCP server with the following code:

var server = ObjectTransport.Factory.CreateTCPServer()
                                    .UseJSONserialization();
                                    .Build();

//Start the TCP server on port 123
server.Start("127.0.0.1",123);

or you can start a UDP server

var server = ObjectTransport.Factory.CreateUDPServer()
                                    .UseJSONserialization();
                                    .Build();

//Start the UDP server on port 123                                    
server.Start("127.0.0.1",123);

Receiving an Object

In this example we have a scenario where we want to handle a user logging into the server. Suppose we have a simple class called "LoginModel". For now this class only has the field "Username"

public class LoginModel
{
        public string Username {get;set;}        
}

We want the server to receive this object and handle it. This can be done using the "Receive" function:

server.Receive<LoginModel>(lm => 
                                {
                                  Console.WriteLine(lm.Username);
                                })
                              .Execute();

In the above code, we specify that when the server Receives an object of type "LoginModel", execute the given lambda. We then write the Username to the console.

It is possible to set up multiple Receive functions and handle other types:

server.Receive<LoginModel>(lm => ... ).Execute();

server.Receive<LogOutModel>(lm => ... ).Execute();

server.Receive<PlayerPosition>(lm => ... ).Execute();
...

Starting the client

You can start a TCP client with the following code:

var client = ObjectTransport.Factory.CreateTCPClient()
                                    .UseJSONserialization();
                                    .Build();

//Start the client and connect to the target IP address and port
client.Start("10.0.0.1",123);

To send an object over the channel, use the "Send" function:

var loginRequest = new LoginModel()
loginRequest.Username = "TestUser";

client.Send(loginRequest).Execute();

Setting up multiple responses

In the following example, we will show how a server/client can reply to a received object.

In our previous example, we are currently sending a Username to the server but not our password, which isn't very secure. In this example, we update our model to have a "Password" field:

public class LoginModel
{
        public string Username {get;set;}        
        public string Password {get;set;}    
}

Sending Login Request from the client

Our client needs to send a login request to the server and will now need to send their password as well. Due to this, we want to handle any responses to our request including whether or not the login was successful. To handle this, we create two new classes "LoginSuccess" and "LoginFailure".

public class LoginSuccess
{
        public string Name {get;set;}        
        public string Password {get;set;}    
}

public class LoginFailure
{
        public string Message {get;set;}                
}

In our client code, we will now use the "Response" function after sending the login object. When the server replies to the object that was sent, the client will handle it's responses:

var transport = ObjectTransport.Factory.CreateTCPClient("10.0.0.1",123);

var loginRequest = new LoginModel();
loginRequest.Username = "TestUser";
loginRequest.Password = "A password";

transport.Send(loginRequest)
        .Response<LoginSuccess>(ls=>{
            Console.WriteLine("Welcome Back {0}", ls.Name);
        })
        .Response<LoginFailure>(lr=>{
            Console.WriteLine(lr.Message)
         })
         .Execute();

In the above example, we setup 2 response handles, one to handle "LoginSuccess" and another to handle "LoginFailure".

On the server, we will use the "Reply" function after receiving a login model. When using this function we need use a function/lambda which will "return" an object that will be sent back:

server.Receive<LoginModel>()
        .Reply(lr=> {
            
            string user = string.empty;
            //Check if login is valid
            
            if(utilities.Login(lr, out user))
            {
            
              //Return an object back to the client
              
              var response = new LoginSuccess();
              response.Message = "Login Successful";
              response.Name = user;
              
              return response;
            }
            else
            {
            
              //Return an object back to the client
              
              var response = new LoginFailure();
              response.Message = "Login Failed";
              
              return response;
            }
        })
        .Execute();

Specifying client to send to

When multiple clients are connected, it is possible to specify which client to send a message to using the "To" function. You can specify multiple clients in the "To" function.

server.Send(anObjectToSend)
         .To(client1,client2, ... ClientN)
         .Execute();

Send to all clients

You can send to all clients using the following.

//Send to all clients
 server.Send(anObjectToSend)
         .ToAll()
         .Execute();
         
//Note that you don't actually need to specify ToAll anymore. By default the API will send to all
         

Send to all clients except given clients

You can also send to all clients and specify who to exclude:

//Send to all clients except client 3
 server.Send(anObjectToSend)
         .ToAllExcept(client3) //Can exclude more eg: .ToAllExcept(client3,client2, ... clientN)
         .Execute();
         

OnConnect / OnDisconnet handles

You can specify what should happen when someone connects or disconnects:

//Setup onconnect handler
transport.OnClientConnect(c => Console.WriteLine("A client has connected with ip {0}",c.IPAddress));

//Setup onDisconnect handler
transport.OnClientDisconnect(c=> Console.WriteLine("A client has disconnected with ip {0}",c.IPAddress));

Sending object reliably

When sending objects over UDP, the message is sent without reliability. You can switch reliably on for UDP on with the following:

 client.SetReliable();

After executing the above line, all objects that are sent will be sent reliably.

Another option is to send only a specific message reliably. The following demonstrates this:

 client.Send(anObjectToSend)
         .Reliable();
         .Execute();

Disconnect Client

To disconnect one ore more clients from the server, you can use the DisconnectClient function:

 server.DisconnectClient(client1,client2, ... clientN);

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].