Git Product home page Git Product logo

pixockets's Introduction

pixockets

A rapid lightweight UDP library. It is specialized for soft realtime applications with heavy per-connection traffic.

Features

  • Small memory traffic
  • Pure C#
  • Optional reliable
  • Optional ordered
  • Big (>MTU) messages fragmentation
  • Can be used without any reliability/ordering/fragmentation overhead
  • IPv6 support
  • Platfroms:
    • Unity3d support
    • .NET Framework, Mono, .NET Core
    • Windows, macOS, Linux, iOS, Android

Usage:

Client

var bufferPool = new ByteBufferPool();
var sock = new SmartSock(bufferPool, new ThreadSock(bufferPool, AddressFamily.InterNetwork, new LoggerStub()), null);
sock.Connect(IPAddress.Loopback, 2345);
var cnt = 0;
var packet = new ReceivedSmartPacket();
while (!Console.KeyAvailable)
{
    while (sock.Receive(ref packet))
    {
        if (sock.State == PixocketState.Connected)
        {
            var buffer = BitConverter.GetBytes(cnt++);
            sock.Send(buffer, 0, buffer.Length, false);
        }
        if (!packet.InOrder)
        {
            Console.WriteLine("!!! OutOfOrder !!!");
        }
        var recv = BitConverter.ToInt32(packet.Buffer, packet.Offset);
        Console.WriteLine("Client Received: {0}", recv);
        bufferPool.Put(packet.Buffer);
    }

    sock.Tick();
    Thread.Sleep(50);
}

sock.Close();

Server

var bufferPool = new ByteBufferPool();
var sock = new SmartSock(bufferPool, new ThreadSock(bufferPool, AddressFamily.InterNetwork, new LoggerStub()), null);
sock.Listen(2345);
var packet = new ReceivedSmartPacket();
while (!Console.KeyAvailable)
{
    while (sock.Receive(ref packet))
    {
        if (!packet.InOrder)
        {
            Console.WriteLine("!!! OutOfOrder !!!");
        }

        var recv = BitConverter.ToInt32(packet.Buffer, packet.Offset);
        Console.WriteLine("Server Received: {0}", recv);
        sock.Send(packet.EndPoint, packet.Buffer, packet.Offset, packet.Length, false);
        bufferPool.Put(packet.Buffer);
    }

    sock.Tick();
    Thread.Sleep(50);
}

sock.Close();

pixockets's People

Contributors

s-yablonskiy avatar agrigorevpix avatar

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.