Coder Social home page Coder Social logo

romanov / litenetlib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from revenantx/litenetlib

0.0 1.0 0.0 609 KB

Lite reliable UDP library for Mono and .NET

Home Page: https://groups.google.com/forum/#!forum/litenetlib

License: MIT License

C# 100.00%

litenetlib's Introduction

LiteNetLib

Lite reliable UDP library for .NET and Mono. Minimal .NET version - 3.5

Build status

Features

  • Simple connection handling
  • Helper classes for sending and reading messages
  • Different send mechanics
  • Reliable with order
  • Reliable without order
  • Ordered but unreliable with duplication prevention
  • Simple UDP packets without order and reliability
  • Packet flow control
  • Automatic fragmentation of reliable packets
  • Automatic MTU detection
  • UDP NAT hole punching
  • NTP time requests
  • Packet loss and latency simulation
  • IPv6 support (dual mode)
  • Connection statisitcs
  • Multicasting (for discovering servers in local network)
  • Small CPU and RAM usage
  • Unity3d support (you can use library source in project)
  • Supported platforms:
  • Windows/Mac/Linux
  • Android
  • iOS
  • Universal Windows (Windows 8.1 and Windows 10 including phones)

Usage samples

Server

EventBasedNetListener listener = new EventBasedNetListener();
NetServer server = new NetServer(listener, 2 /* maximum clients */, "SomeConnectionKey");
server.Start(9050 /* port */);

listener.PeerConnectedEvent += peer =>
{
    Console.WriteLine("We got connection: {0}", peer.EndPoint); // Show peer ip
    NetDataWriter writer = new NetDataWriter();                 // Create writer class
    writer.Put("Hello client!");                                // Put some string
    peer.Send(writer, SendOptions.ReliableOrdered);             // Send with reliability
};

while (!Console.KeyAvailable)
{
    server.PollEvents();
    Thread.Sleep(15);
}

server.Stop();

Client

EventBasedNetListener listener = new EventBasedNetListener();
NetClient client = new NetClient(listener, "SomeConnectionKey");
client.Start();
client.Connect("localhost" /* host ip or name */, 9050 /* port */);
listener.NetworkReceiveEvent += (fromPeer, dataReader) =>
{
    Console.WriteLine("We got: {0}", dataReader.GetString(100 /* max length of string */));
};

while (!Console.KeyAvailable)
{
    client.PollEvents();
    Thread.Sleep(15);
}

client.Stop();

Client and server setting description

  • UnconnectedMessagesEnabled
  • enable messages receiving without connection. (with SendUnconnectedMessage method)
  • default value: false
  • NatPunchEnabled
  • enable nat punch messages
  • default value: false
  • UpdateTime
  • library logic update (and send) period in milliseconds
  • default value: 100 msec. For games you can use 15 msec (66 ticks per second)
  • ReliableResendTime
  • time for resending lost reliable packets in milliseconds
  • default value: 500 msec. Set that value to 4x-5x update time ( if UpdateTime = 15 then ReliableResendTime = 75 )
  • PingInterval
  • Interval for latency detection and checking connection
  • default value: 1000 msec.
  • DisconnectTimeout
  • if client or server doesn't receive any packet from remote peer during this time then connection will be closed
  • default value: 5000 msec.
  • SimulatePacketLoss
  • simulate packet loss by dropping random amout of packets. Works only in DEBUG mode
  • default value: false
  • SimulateLatency
  • simulate latency by holding packets for random time
  • default value: false
  • SimulationPacketLossChance
  • chance of packet loss when simulation enabled. value in percents.
  • default value: 10 (%)
  • SimulationMaxLatency
  • maximum simulated latency ( it will be random from 0 to value )
  • default value: 100 msec
  • UnsyncedEvents
  • Experimental feature. Events automatically will be called without PollEvents method from another thread
  • default value: false
  • DiscoveryEnabled
  • Allows receive DiscoveryRequests
  • default value: false

Only client

  • ReconnectDelay
  • delay betwen connection attempts
  • default value: 500 msec
  • MaxConnectAttempts
  • maximum connection attempts before client stops and call disconnect event.
  • default value: 10
  • PeerToPeerMode
  • allows client connect to other client
  • default value: false

litenetlib's People

Contributors

revenantx avatar romanov avatar

Watchers

 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.