Exemple #1
0
        /// <summary>
        /// Sends the data succeed.
        /// </summary>
        /// <param name="sendData">The send data.</param>
        private void SendDataSucceed(byte[] sendData)
        {
            if (ConnectTcpClient.Connected)
            {
                if (tcpClientStream == null)
                {
                    tcpClientStream = ConnectTcpClient.GetStream();
                }

                byte[] _buffer = sendData;
                tcpClientStream.Write(_buffer, 0, _buffer.Length);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends the data succeed.
        /// </summary>
        /// <param name="sendData">The send data.</param>
        private void SendDataSucceed(string sendData)
        {
            if (ConnectTcpClient.Connected)
            {
                if (tcpClientStream == null)
                {
                    tcpClientStream = ConnectTcpClient.GetStream();
                }

                byte[] _buffer = Encoding.UTF8.GetBytes(sendData);
                tcpClientStream.Write(_buffer, 0, _buffer.Length);
            }
        }
Exemple #3
0
 /// <summary>
 /// 连接到Server
 /// </summary>
 public void Connect()
 {
     try
     {
         ConnectTcpClient.Connect(TcpClientIpEndPoint);
         tcpClientStream           = new NetworkStream(ConnectTcpClient.Client, true);
         TcpClientConnectedSeesion = new TcpClientConnectSession(TcpClientIpEndPoint, ConnectTcpClient, tcpClientStream);
         TcpClientConnectedSeesion.SkStream.BeginRead(recBuffer, 0, recBuffer.Length, new AsyncCallback(EndReader), TcpClientConnectedSeesion);
         RaiseDataReceivedEvent(TcpOperateEventCode.ConnectSuccess, null, null, TcpClientIpEndPoint, null);
     }
     catch (Exception ex)
     {
         RaiseDataReceivedEvent(TcpOperateEventCode.ConnectError, null, ex, TcpClientIpEndPoint, null);
     }
 }
Exemple #4
0
        /// <summary>
        /// 端口与Server的连接
        /// </summary>
        public void Disconnect()
        {
            TcpClientConnectSession _connectedSession = new TcpClientConnectSession();

            if (ConnectTcpClient != null)
            {
                ConnectTcpClient.Client.Shutdown(SocketShutdown.Both);
                Thread.Sleep(10);
                ConnectTcpClient.Close();
                isClose          = true;
                ConnectTcpClient = null;
                RaiseDataReceivedEvent(TcpOperateEventCode.CliendDisconnected, null, null, TcpClientIpEndPoint, null);
            }
            else
            {
                RaiseDataReceivedEvent(TcpOperateEventCode.ClientUninitialized, null, null, TcpClientIpEndPoint, null);
            }
        }