コード例 #1
0
        /// <summary>
        /// Called when [TCP client socket closed].
        /// </summary>
        /// <param name="eventObj">The <see cref="Event"/> object.</param>
        private void OnClientSocketClosed(Event eventObj)
        {
            SocketEvent   socketEvent = (SocketEvent)eventObj;
            MonoTcpClient tcpClient   = socketEvent.TcpClient;

            DispatchEvent(new SocketEvent(SocketEvent.ClientClosed, tcpClient));
        }
コード例 #2
0
        /// <summary>
        /// Called when [TCP client got error].
        /// </summary>
        /// <param name="eventObj">The <see cref="Event"/> object.</param>
        private void OnClientSocketException(Event eventObj)
        {
            SocketEvent   socketEvent = (SocketEvent)eventObj;
            MonoTcpClient tcpClient   = socketEvent.TcpClient;
            Exception     ex          = socketEvent.Exception;

            DispatchEvent(new SocketEvent(SocketEvent.ClientExceptionCaught, tcpClient, ex));
        }
コード例 #3
0
        /// <summary>
        /// Called when [TCP client socket received data].
        /// </summary>
        /// <param name="eventObj">The <see cref="Event"/> object.</param>
        private void OnClientSocketDataReceived(Event eventObj)
        {
            SocketEvent   socketEvent  = (SocketEvent)eventObj;
            MonoTcpClient tcpClient    = socketEvent.TcpClient;
            ISocketPacket socketPacket = socketEvent.SocketPacket;

            DispatchEvent(new SocketEvent(SocketEvent.ClientDataReceived, tcpClient, socketPacket));
        }
コード例 #4
0
        /// <summary>
        /// Initializes the <see cref="System.Net.Sockets.TcpClient"/>.
        /// </summary>
        /// <param name="client">The <see cref="System.Net.Sockets.TcpClient"/>.</param>
        /// <param name="packetHandler">The <see cref="ISocketPacketHandler"/> for handling socket packets.</param>
        /// <returns>The <see cref="TcpClientBase"/> that was converted.</returns>
        protected override TcpClientBase InitializeTcpClient(System.Net.Sockets.TcpClient client, ISocketPacketHandler packetHandler)
        {
            MonoTcpClient tcpClient = new MonoTcpClient(client, packetHandler);

            tcpClient.AddEventListener(SocketEvent.SocketConnected, OnClientSocketConnected);
            tcpClient.AddEventListener(SocketEvent.SocketDisconnected, OnClientSocketDisconnected);
            tcpClient.AddEventListener(SocketEvent.SocketDataReceived, OnClientSocketDataReceived);
            tcpClient.AddEventListener(SocketEvent.SocketClosed, OnClientSocketClosed);
            tcpClient.AddEventListener(SocketEvent.ExceptionCaught, OnClientSocketException);
            return(tcpClient);
        }
コード例 #5
0
 /// <summary>
 /// Disposes the <see cref="TcpClientBase"/>.
 /// </summary>
 /// <param name="client">The <see cref="TcpClientBase"/> that need to be disposed.</param>
 protected override void DisposeTcpClient(TcpClientBase client)
 {
     if (client != null)
     {
         MonoTcpClient tcpClient = (MonoTcpClient)client;
         tcpClient.RemoveEventListener(SocketEvent.SocketConnected, OnClientSocketConnected);
         tcpClient.RemoveEventListener(SocketEvent.SocketDisconnected, OnClientSocketDisconnected);
         tcpClient.RemoveEventListener(SocketEvent.SocketDataReceived, OnClientSocketDataReceived);
         tcpClient.RemoveEventListener(SocketEvent.SocketClosed, OnClientSocketClosed);
         tcpClient.RemoveEventListener(SocketEvent.ExceptionCaught, OnClientSocketException);
     }
 }
コード例 #6
0
        /// <summary>
        /// Update is called every frame.
        /// </summary>
        public void Update()
        {
            if (eventDispatcher != null)
            {
                eventDispatcher.Update();
            }

            foreach (KeyValuePair <IPEndPoint, TcpClientBase> kvp in Clients)
            {
                if (kvp.Value != null)
                {
                    MonoTcpClient tcpClient = (MonoTcpClient)kvp.Value;
                    tcpClient.Update();
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketEvent"/> class with event type and <see cref="MonoTcpClient"/> instance.
 /// </summary>
 /// <param name="eventType">The type of the event.</param>
 /// <param name="client">The instance of <see cref="MonoTcpClient"/>.</param>
 /// <param name="exception">The <see cref="Exception"/> caught.</param>
 public SocketEvent(string eventType, MonoTcpClient client, Exception exception)
     : base(eventType, client)
 {
     Exception = exception;
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketEvent"/> class with event type and <see cref="MonoTcpClient"/> instance.
 /// </summary>
 /// <param name="eventType">The type of the event.</param>
 /// <param name="client">The instance of <see cref="MonoTcpClient"/>.</param>
 /// <param name="packet">The <see cref="ISocketPacket"/> unpacked.</param>
 public SocketEvent(string eventType, MonoTcpClient client, ISocketPacket packet = null)
     : base(eventType, client)
 {
     SocketPacket = packet;
 }