private void Send(BinaryWriter bw, RemoteCommand cmd) { Utility.StreamWriteBytes(bw, cmd.GenerateMessage()); // Hope this flushes buffers! bw.Flush(); }
/// <returns>true: continue, false:end</returns> private bool RecvRequests(BinaryReader br) { bool bContinue = true; int header = Utility.StreamReadInt32(br); long bytes = Utility.StreamReadInt64(br); if (bytes < 0 || RECV_TOO_LARGE < bytes) { return(false); } var payload = new byte[0]; if (0 < bytes) { payload = Utility.StreamReadBytes(br, (int)bytes); } var cmd = new RemoteCommand(header, (int)bytes, payload); if (cmd.cmd == RemoteCommandType.Exit) { Console.WriteLine("D: PPWServer RemoteCommand EXIT received\n"); bContinue = false; } //Console.WriteLine("PPWServer RecvRequests {0} {1}", DateTime.Now.Second, cmd.cmd); mRemoteCmdRecvDelegate(cmd); return(bContinue); }
private void SendQueuedMsg(BinaryWriter bw) { int sendCmdCount = 0; lock (mLock) { sendCmdCount = mCmdToSend.Count; } while (0 < sendCmdCount) { RemoteCommand rc = null; lock (mLock) { rc = mCmdToSend[0]; } //Console.WriteLine("PPWServer SendQueuedMsg() {0} Sending {1}", DateTime.Now.Second, rc.cmd); Send(bw, rc); lock (mLock) { mCmdToSend.RemoveAt(0); sendCmdCount = mCmdToSend.Count; } } }
public void SendAsync(RemoteCommand cmd) { lock (mLock) { mCmdToSend.Add(cmd); } }