Пример #1
0
        public bool Send(ITransferable packet, object userData = null)
        {
            if (_connected == 0)
            {
                return(false);
            }

            try
            {
                //Send data
                byte[] byteBuffer = packet.Serialize();
                int    dataLength = byteBuffer.Length;
                _networkStream.Write(byteBuffer, 0, dataLength);

                //Fire DataSent event
                if (DataSent != null)
                {
                    DataSent(packet, userData);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (DataSendError != null)
                {
                    DataSendError(packet, userData, ex);
                }
                Disconnect();
            }

            return(false);
        }
Пример #2
0
        public bool Send(TCPClientEx tcpClient, ITransferable packet, object userData = null)
        {
            if (!tcpClient.Connected)
            {
                return(false);
            }

            try
            {
                //Send data
                byte[] byteBuffer = packet.Serialize();
                int    dataLength = byteBuffer.Length;
                ((TcpClient)tcpClient).GetStream().Write(byteBuffer, 0, dataLength);

                //Fire DataSent event
                if (ClientDataSent != null)
                {
                    ClientDataSent(tcpClient, packet, userData);
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (ClientDataSendError != null)
                {
                    ClientDataSendError(tcpClient, packet, userData, ex);
                }
            }
            return(false);
        }
Пример #3
0
        public void Send(int clientId, ITransferable packet)
        {
            //Serialize data
            byte[] dataToSend = packet.Serialize();

            //Send data
            Send(clientId, dataToSend);
        }
Пример #4
0
        public void Send(ITransferable packet)
        {
            //Serialize data
            byte[] dataToSend = packet.Serialize();

            //Send data
            Send(dataToSend);
        }
Пример #5
0
        public bool Send(ITransferable packet, object userData = null)
        {
            if (_connected == 0)
            {
                return false;
            }

            try
            {
                //Send data
                byte[] byteBuffer = packet.Serialize();
                int dataLength = byteBuffer.Length;
                _networkStream.Write(byteBuffer, 0, dataLength);

                //Fire DataSent event
                if (DataSent != null)
                {
                    DataSent(packet, userData);
                }

                return true;
            }
            catch (Exception ex)
            {
                if (DataSendError != null)
                {
                    DataSendError(packet, userData, ex);
                }
                Disconnect();
            }

            return false;
        }
Пример #6
0
        public void Send(int clientId, ITransferable packet)
        {
            //Serialize data
            byte[] dataToSend = packet.Serialize();

            //Send data
            Send(clientId, dataToSend);
        }
Пример #7
0
        public bool Send(TCPClientEx tcpClient, ITransferable packet, object userData = null)
        {
            if (!tcpClient.Connected)
            {
                return false;
            }

            try
            {
                //Send data
                byte[] byteBuffer = packet.Serialize();
                int dataLength = byteBuffer.Length;
                ((TcpClient) tcpClient).GetStream().Write(byteBuffer, 0, dataLength);

                //Fire DataSent event
                if (ClientDataSent != null)
                {
                    ClientDataSent(tcpClient, packet, userData);
                }

                return true;
            }
            catch (Exception ex)
            {
                if (ClientDataSendError != null)
                {
                    ClientDataSendError(tcpClient, packet, userData, ex);
                }
            }
            return false;
        }