Beispiel #1
0
 private void OnActionReceive(object sender, SocketAsyncEventArgs e)
 {
     for (int i = 0; i < e.BytesTransferred; i++)
     {
         if (e.Buffer[i] == ';')
         {
             StringBuilder sb = new StringBuilder();
             foreach (byte b in rcvbuf)
             {
                 sb.Append((char)b);
             }
             string[] str = MsgPackager.Splitter(sb.ToString()), datas = new string[str.Length - 1];
             for (int j = 1; j < str.Length; j++)
             {
                 datas[j - 1] = str[j];
             }
             mt.TranslateMessage(str[0], datas);
             rcvbuf.Clear();
         }
         else
         {
             rcvbuf.Add(e.Buffer[i]);
         }
     }
     e.SetBuffer(0, plength);
     socket.ReceiveAsync(e);
 }
Beispiel #2
0
        public void ServerListen()
        {
            byte[] data = new byte[plength];
            while (true)
            {
                int len = socket.Receive(data);
                if (len == 0)
                {
                    count++;
                }
                else
                {
                    count = 0;
                }
                if (count > 10)
                {
                    throw new Exception("远程移动设别主动关闭了所保持的连接!");
                }

                for (int i = 0; i < len; i++)
                {
                    if (data[i] == ';')
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (byte b in rcvbuf)
                        {
                            sb.Append((char)b);
                        }
                        string   str  = sb.ToString();
                        string[] strs = MsgPackager.Splitter(str), datas = new string[strs.Length - 1];
                        for (int j = 1; j < strs.Length; j++)
                        {
                            datas[j - 1] = strs[j];
                        }
                        mt.TranslateMessage(strs[0], datas);
                        rcvbuf.Clear();
                    }
                    else
                    {
                        rcvbuf.Add(data[i]);
                    }
                }
            }
        }
Beispiel #3
0
 public static String GetSendUserString(String userid, String password)
 {
     return(MsgPackager.Packager(new string[] { "log", userid, password }));
 }