Git Product home page Git Product logo

raknet_networking's Introduction

RakNet_Networking

This is a ready-made network solution for the Unity3D engine based on the cross-platform network engine RakNet that previously existed in Unity ...

The source code has a demo scene in which there are 2 scripts showing the network interaction between the client and the server.

Examples

For send packets from a client or server, you first need to write data to a binary stream.

              
                if (m_NetworkWriter.StartWritting())
                {
                    m_NetworkWriter.WritePacketID((byte)PACKET_ID);
                    m_NetworkWriter.Write("example string");
                    m_NetworkWriter.WritePackedUInt64(1234);
                    
                    //If you need to send from the server, you must specify the net_id connection from the Connection class
                    //If from the client to the server you need to specify local_id from the ClientNetInfo class
                    ulong guid = 0;
                    
                    m_NetworkWriter.Send(guid, Peer.Priority.Immediate, Peer.Reliability.Reliable, 0);
                }

For read data from a binary stream, use the sample code below.

             {
                //Since the stream is cleared when the network stream is received, there is no need to use the
                //m_NetworkReader.StartReading () check, because, as shown in the demo version, the stream is 
                //cleared and then reads the first byte to identify the packet number, then 
                //the method is called OnReceivedPacket (byte) taking the packet number as an argument and 
                //there it is already processed by code using the m_NetworkReader class functional
                string s = m_NetworkReader.ReadString();//receiving text 'example string'
                ulong _integer64 = m_NetworkReader.ReadPacketUInt64();
             }

It is very important to use the sequence of writing to the stream, otherwise, if the data is not written sequentially, errors and exceptions will occur.

Suppose you have written a string to a stream and are trying to read a number from it

Using this class you can easily upgrade the code to encrypt the data sent.

raknet_networking's People

Contributors

redheadgektor 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.