示例#1
0
 private void MessageForm(string messagee)
 {
     try
     {
         T_Roomi.Text += messagee;
     }
     catch (Exception ex)
     {
         ToastUtils.Show(this, ex.Message);
     }
 }
示例#2
0
 private void SetupConnection()
 {
     try
     {
         SocketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         Ipeserver    = new IPEndPoint(IP, Port);
         SocketClient.BeginConnect(Ipeserver, new AsyncCallback(ConnectCallback), SocketClient);
     }
     catch (Exception ex)
     {
         ToastUtils.Show(this, ex.Message);
     }
 }
示例#3
0
        private void SendData(Socket socket, string msg)
        {
            try
            {
                buffer = Encoding.Unicode.GetBytes(msg);

                socket.BeginSend(buffer, 0, buffer.Length,
                                 SocketFlags.None, new AsyncCallback(SendCallback), socket);
            }
            catch (Exception ex)
            {
                //Toast.MakeText(this, ex.Message, ToastLength.Short).Show();
                ToastUtils.Show(this, ex.Message);
            }
        }
示例#4
0
        private void ConnectCallback(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;

            try
            {
                socket.EndConnect(ar);

                T_Roomi.Text +=
                    string.Format("{0} {1}", DateTime.Now.ToString("hh,mm,ss"), "Connected Server\n");

                SocketClient.BeginReceive(buffer, 0, buffer.Length,
                                          SocketFlags.None, new AsyncCallback(ReceiveCallback), socket);
            }
            catch (Exception ex)
            {
                ToastUtils.Show(this, ex.Message);
            }
        }
示例#5
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;

            try
            {
                int    recive        = socket.EndReceive(ar);
                string reciveMessage = Encoding.Unicode.GetString(buffer, 0, recive);

                MessageForm(reciveMessage + "\n");

                SocketClient.BeginReceive(buffer, 0, buffer.Length,
                                          SocketFlags.None, new AsyncCallback(ReceiveCallback), socket);
            }
            catch (Exception ex)
            {
                //Toast.MakeText(this, ex.Message, ToastLength.Short).Show();
                ToastUtils.Show(this, ex.Message);
            }
        }