GithubHelp home page GithubHelp logo

fexolm / gserver Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 4.0 7.5 MB

Easy for use, game developing oriented reliable udp library

License: MIT License

C# 100.00%
udp reliable-udp game-server dotnet csharp gserver networking unity3d

gserver's Introduction

GServer

About GServer

Usage

Classes

Examples

What is GServer

GServer is reliable UDP networking library, designed for games. Its main advantages are:

What is reliable UDP

Reliable udp (RUDP) is a transport layer protocol designed for situations where TCP adds too much overhead, but nonetheless we need guaranteed-order packet delivery.

RUDP mods

RUDP supports 3 mods and their combinations. GServer implements some of the most useful of them:

  • No mode - works like standard UDP
  • Reliable - provides delivery checking and guarantees that all packages will be delivered
  • Reliable sequenced - guarantees that all packages that are delivered will be processed in correct order, but no implication of delivering all packages is made
  • Reliable ordered - guarantees that all packages will be delivered and will be processed in correct order

Why reliable udp is better than tcp

  • Reliable udp provides more flexibility than udp because of it's modes
  • Reliable ordered mode simulates tcp behavior but works faster since it doesn't need to wait for lost packages.

Classes

Host

Host is the main class in GServer. It provides methods to receive, send and process messages. Messages are accept automatically in listen thread.

Messages are send using the "Send" method and processed with handlers, which is registered by user using the "AddHandler" method. See examples.

Message

Messages are used to send data from one host to another. It has 3 parameters:

  • type : short - message type which is used to add handler to specific messages.
  • mode : Mode - reliable mode (see RUDP mods)
  • body : byte[] - serialized data in an array of bytes

DataStorage

DataStorage is used to serialize data into byte array. It has 2 mods:

  • Calling the constructor without params enables write only mode.
  • Calling the constructor with byte[] or MemoryStream param enables read only mode.

In read only mode you could use just Read methods which are reading data from buffer. In write only mode you could use just Write methods which are writing data into buffer.

Plugins

In process ...

Examples

Start server

server

Host host= new Host(portNumber); //instantiate host on portNumber port
host.StartListen(numberOfThreads); //StartListen on numberOfThreads threads

Timer timer = new Timer(o=>host.Tick());
timer.Change(10,10); // enables timer tick every 10 milliseconds

client

Host host= new Host(portNumber); //instantiate host on portNumber port
host.StartListen(numberOfThreads); //StartListen on numberOfThreads threads

Timer timer = new Timer(o=>host.Tick());
timer.Change(10,10); // enables timer tick every 10 milliseconds

host.OnConnect = () => Console.WriteLine("Connected"); // connect handler 

host.BeginConnect(serverEndpoint); // connecting to server endpoint

Handling messages

/* host inicialization here */

//add handler to message with id == messageId
//when message with that id will arrive callback will be invoked
//connection - connection associated with sender
host.AddHanlder(messageId, (message, connection) => 
{
    /* deserialize message buffer */
    /* process message buffer */
    /* send response if needed */
});

DataStorage

class SimpleClass : ISerializable, IDeserializable 
{
     public int IntField {get;set;}
     public byte[] ByteArray {get;set} // arraySize = IntField
     public byte[] Serialize() 
     {
          var ds = DataStorage.CreateForWrite();
          ds.Push(IntField);
          ds.Push(ByteArray);
          return ds.Serialize();
     }
     public void FillDeserialize(byte[] buffer)
     {
          var ds = DataStorage.CreateForRead(buffer);
          IntField = ds.ReadInt32();
          ByteArray = ds.ReadBytes(IntField);
     }
}

gserver's People

Contributors

bumac avatar fexolm avatar nefillim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gserver's Issues

Buffer overflow

Buffer overflows while attempting to send huge amount of messages

Unity support

Unable to use this in Unity 2019, as system.reflection and system.reflection.emit not unavailable in unity. Any way to use this in unity

Thanks

Changing name

I think we need to change project name.
So, please place your ideas (if you have some) in comments.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.