Exemple #1
0
        private void ConnectCallback(IAsyncResult result)
        {
            try
            {
                //We are connected successfully
                NetworkStream network_stream = mTcpClient.GetStream();

                byte[] buffer = new byte[mTcpClient.ReceiveBufferSize];

                //Now we are connected start asyn read operation
                network_stream.BeginRead(buffer, 0, buffer.Length, ReadCallback, buffer);

                if (mBufferSream == null)
                {
                    mBufferSream          = new MemoryStream();
                    mBufferSream.Capacity = MESSAGE_BUFFER_SIZE;
                }
                else
                {
                    mBufferSream.SetLength(0);                      // "clearing" buffer
                }

                mConnected = true;

                if (OnConnectionSucceeded != null)
                {
                    OnConnectionSucceeded.Invoke();
                }
            }
            catch (Exception)
            {
                //Debug.Log("[SnipeTCPClient] ConnectCallback: " + e.Message);

                mConnected = false;

                // send event
                if (OnConnectionFailed != null)
                {
                    OnConnectionFailed.Invoke();
                }
            }
        }
 public void ConnectionSucceeded()
 {
     OnConnectionSucceeded?.Invoke(this);
 }