Пример #1
0
        /// <summary>
        /// Creates a socket that will send and receive messages
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="sendPort"></param>
        /// <param name="receivePort"></param>
        /// <param name="type"></param>
        /// <param name="timeout"></param>
        /// <param name="initialEmit"></param>
        /// <returns></returns>
        public static SocketIo Create(string ip, ushort sendPort, ushort receivePort, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
        {
            SocketIo socket = SocketIo.CreateSender <JsonSerializer>(ip, sendPort, timeout, type, initialEmit);

            socket.AddListener(receivePort);
            return(socket);
        }
Пример #2
0
        /// <summary>
        /// Creates a socket that will send and receive messages
        /// </summary>
        /// <typeparam name="T">The type of serializer used.</typeparam>
        /// <param name="ip"></param>
        /// <param name="sendPort"></param>
        /// <param name="receivePort"></param>
        /// <param name="type"></param>
        /// <param name="timeout"></param>
        /// <param name="initialEmit"></param>
        /// <returns></returns>
        public static async Task <SocketIo> CreateAsync <T>(string ip, ushort sendPort, ushort receivePort, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
            where T : ISerializer, new()
        {
            SocketIo socket = await SocketIo.CreateSenderAsync <T>(ip, sendPort, timeout, type, initialEmit);

            socket.AddListener(receivePort);
            return(socket);
        }
Пример #3
0
        /// <summary>
        /// Creates a socket that will send and receive messages
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="type"></param>
        /// <param name="timeout"></param>
        /// <param name="initialEmit"></param>
        public static async Task <SocketIo> CreateAsync(string ip, ushort port, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
        {
            var receivePort = GetOpenPort(port);

            SocketIo socket = await SocketIo.CreateSenderAsync <JsonSerializer>(ip, port, timeout, type, initialEmit);

            socket.AddListener(receivePort);
            return(socket);
        }
Пример #4
0
        /// <summary>
        /// Creates a socket that will send and receive messages
        /// </summary>
        /// <typeparam name="T">The type of serializer used.</typeparam>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="type"></param>
        /// <param name="timeout"></param>
        /// <param name="initialEmit"></param>
        public static SocketIo Create <T>(string ip, ushort port, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
            where T : ISerializer, new()
        {
            var receivePort = GetOpenPort(port);

            SocketIo socket = SocketIo.CreateSender <T>(ip, port, timeout, type, initialEmit);

            socket.AddListener(receivePort);
            return(socket);
        }
Пример #5
0
        private static SocketIo SetupSocketHandler <T>(string ip, ushort sendPort, ushort receivePort, int timeout, SocketHandlerType socketType)
            where T : ISerializer, new()
        {
            var socket = new SocketIo
            {
                ConnectedIP = ip,
                SendPort    = sendPort,
                ReceivePort = receivePort,
                Timeout     = timeout,
            };

            socket.SetupSerializer <T>();

            if (socket.Handler == null)
            {
                switch (socketType)
                {
                case SocketHandlerType.Tcp:
                    socket.Handler = new TCPHandler(ip, socket.SendPort, socket.ReceivePort, socket.Timeout, socket);
                    break;

                case SocketHandlerType.Udp:
                    socket.Handler = new UDPHandler(ip, socket.SendPort, socket.ReceivePort, socket.Timeout, socket);
                    break;

                case SocketHandlerType.WebSocket:
                    socket.Handler = new WebSocketHandler(ip, socket.SendPort, socket.ReceivePort, socket.Timeout, socket);
                    break;
                }
            }
            else
            {
                socket.Handler.Setup(socket.ConnectedIP, socket.SendPort, socket.ReceivePort, socket.Timeout);
            }

            return(socket);
        }
Пример #6
0
 /// <summary>
 /// Creates a socket that will receive messages
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="receivePort"></param>
 /// <param name="type"></param>
 /// <param name="timeout"></param>
 /// <returns></returns>
 public static SocketIo CreateListener(string ip, ushort receivePort, SocketHandlerType type, int timeout = DefaultTimeout)
 {
     return(SocketIo.CreateListener <JsonSerializer>(ip, receivePort, timeout, type));
 }
Пример #7
0
 /// <summary>
 /// Adds a sender to the socket
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="sendPort"></param>
 /// <param name="initialEmit"></param>
 /// <returns></returns>
 public static SocketIo AddSender(this SocketIo socket, ushort sendPort, string initialEmit = null)
 {
     socket.AddSender(sendPort, initialEmit);
     return(socket);
 }
Пример #8
0
        /// <summary>
        /// Adds a sender to the socket
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="sendPort"></param>
        /// <param name="initialEmit"></param>
        /// <returns></returns>
        public static async Task <SocketIo> AddSenderAsync(this SocketIo socket, ushort sendPort, string initialEmit = null)
        {
            await socket.AddSenderAsync(sendPort, initialEmit);

            return(socket);
        }
Пример #9
0
 /// <summary>
 /// Adds a listener to the socket
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="receivePort"></param>
 /// <returns></returns>
 public static SocketIo AddListener(this SocketIo socket, ushort receivePort)
 {
     socket.Connect(receivePort);
     return(socket);
 }
Пример #10
0
 /// <summary>
 /// Creates a socket that will send messages
 /// </summary>
 /// <typeparam name="T">The type of serializer used.</typeparam>
 /// <param name="ip"></param>
 /// <param name="sendPort"></param>
 /// <param name="type"></param>
 /// <param name="timeout"></param>
 /// <param name="initialEmit"></param>
 /// <returns></returns>
 public static SocketIo CreateSender(string ip, ushort sendPort, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
 {
     return(SocketIo.CreateSender <JsonSerializer>(ip, sendPort, timeout, type, initialEmit));
 }
Пример #11
0
 /// <summary>
 /// Creates a socket that will send messages
 /// </summary>
 /// <typeparam name="T">The type of serializer used.</typeparam>
 /// <param name="ip"></param>
 /// <param name="sendPort"></param>
 /// <param name="type"></param>
 /// <param name="timeout"></param>
 /// <param name="initialEmit"></param>
 /// <returns></returns>
 public static async Task <SocketIo> CreateSenderAsync(string ip, ushort sendPort, SocketHandlerType type, int timeout = DefaultTimeout, string initialEmit = null)
 {
     return(await SocketIo.CreateSenderAsync <JsonSerializer>(ip, sendPort, timeout, type, initialEmit));
 }