// returns TCPIPconnector.kClientLeft when client has left protected string ServerRead(Socket sender) { string result = ""; if (this.type == TCPIPconnector.Server) { DataBox box = new DataBox(); box.socket = sender; box.mutex.Reset(); if ((box.socket != null) && (box.socket.Connected)) { box.socket.BeginReceive(box.buffer, 0, DataBox.bufferSize, 0, new AsyncCallback(ServerReadCallback), box); box.mutex.WaitOne(); } else { box.response = TCPIPconnector.kClientLeft; } result = box.response; } return result; }
protected byte[] ServerReadObject(Socket sender) { byte[] rslt = new byte[DataBox.bufferSize]; if (this.type == TCPIPconnector.Server) { DataBox box = new DataBox(); box.socket = sender; box.mutex.Reset(); if ((box.socket != null) && (box.socket.Connected)) { box.socket.BeginReceive(box.buffer, 0, DataBox.bufferSize, 0, new AsyncCallback(ServerReadCallback), box); box.mutex.WaitOne(); rslt = box.buffer; } else { box.response = TCPIPconnector.kClientLeft; rslt = null; } } return rslt; }
// returns null if the server has left protected byte[] ReadObject() { byte[] rslt = new byte[DataBox.bufferSize]; if (this.type == TCPIPconnector.Client) { DataBox box = new DataBox(); box.socket = this.sock; this.clientReceive.Reset(); this.clientReading = true; this.sock.Receive(box.buffer, 0, DataBox.bufferSize, 0); this.clientReading = false; this.clientReceive.Set(); rslt = box.buffer; string result = Encoding.ASCII.GetString(box.buffer, 0, box.buffer.Length).TrimEnd('\0'); if (result == "!closeMe") { result = ""; } if (result == "!closeYou") { this.clientConnected = false; if (this.sock.Connected) { this.sock.Disconnect(false); } result = TCPIPconnector.kServerLeft; rslt = null; } this.clientResponse = ""; } return rslt; }