예제 #1
0
        public static void ShowQ(int i)
        {
            setM  = Q2;
            setM += Q3;

            setM(i);
        }
예제 #2
0
        public void RecM()
        {
            while (true)
            {
                try
                {
                    //容器:暂存来自服务端的信息
                    byte[] msg = new byte[100];

                    //存入信息+获得信息长度
                    int length = socketClient.Receive(msg);

                    //msg转换成字符串
                    string strRevMsg = Encoding.UTF8.GetString(msg, 0, length);

                    //比较获得的指令,并回复
                    if ("send message".Equals(strRevMsg))
                    {
                        SetM?.Invoke(strRevMsg);
                        ClientSendMsg("OK");
                        return;
                    }
                    else
                    {
                        SetM?.Invoke(strRevMsg);
                        ClientSendMsg("error");
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
        /// <summary>  
                 /// 接收消息  
                 /// </summary>  
                 /// <param name="clientSocket"></param>  
                private void ReceiveMessage(object clientSocket)
        {
            Socket myClientSocket = (Socket)clientSocket;

            while (true)
            {
                try
                {  
                  byte[] result = new byte[100];
                  int    length = myClientSocket.Receive(result);
                  SetM?.Invoke(Encoding.UTF8.GetString(result)); }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }