Skip to content

a server/client side socket library integrated with google protobuf for unity3d project.

License

Notifications You must be signed in to change notification settings

caochao/UnitySocketLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnitySocketLib

A server/client side Socket/WebSocket library integrated with google protobuf(v3.11.4) for unity3d project.

Features:

  • 1.The same codes and same workflows for server/client side use.
  • 2.Extensible socket data packer/unpacker. Built-in with Google protobuf packer, but can easily to implement json/string packer.
  • 3.Packet handler based on messaging system.
  • 4.Multiple sessions/channels.

How to use:

    public enum Server
    {
        LoginServer,
        GameServer,
    }
    
    public class NetworkController
    {
        private BaseNetwork _network;

        public NetworkController()
        {
            _network = new BaseNetwork(NetworkProtocol.TCP, new ProtobufPacker());
            _network.SetMsgDispatcher(new NetworkMsgDispatcher());
        }

        public void CreateSession(string address, Server server = Server.GameServer)
        {
            _network.CreateSession((long)server, address);
        }
        
        public UniTask<INetworkMessage> Call(INetworkMessage message, Server server = Server.GameServer)
        {
            return _network.Call(message, (long) server);
        }

        public void Send(INetworkMessage message, Server server = Server.GameServer)
        {
            _network.Send(message, (long) server);
        }

        public void OnUpdate()
        {
            _network.Update();
        }

        public void OnDestroy()
        {
            _network.Dispose();
            _network = null;
        }
    }

About

a server/client side socket library integrated with google protobuf for unity3d project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published