private void doChat() { int requestCount = 0; int buffSize = 10 * 1024; byte[] bytesFrom = new byte[buffSize]; string dataFromClient = null; Byte[] sendBytes = null; string serverResponse = null; string rCount = null; requestCount = 0; NetworkStream networkStream = clientSocket.GetStream(); networkStream.ReadTimeout = 50; serverResponse = "ACK:(" + clNo + ")." + rCount + "\0"; sendBytes = Encoding.ASCII.GetBytes(serverResponse); networkStream.Write(sendBytes, 0, sendBytes.Length); networkStream.Flush(); //var engine = new Engine().SetValue("log", new Action<object>(getString)); var engine = new Engine(cfg => cfg.AllowClr()); engine.SetValue("log", new Action <object>(getString)); engine.SetValue("Color", new System.Drawing.Color()); indy ui = new indy(); engine.SetValue("ui", ui); running = true; while (running) { try { requestCount = requestCount + 1; networkStream.Read(bytesFrom, 0, bytesFrom.Length); dataFromClient = Encoding.ASCII.GetString(bytesFrom); dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf('\0')); messageDisplay.displayStatusText("Received code from client No. " + clNo); rCount = Convert.ToString(requestCount); outputMessage = "ok_tx\n"; try { engine.Execute(dataFromClient); } catch (Exception e) { outputMessage = e.ToString(); } sendBytes = Encoding.ASCII.GetBytes(outputMessage); networkStream.Write(sendBytes, 0, sendBytes.Length); messageDisplay.displayStatusText("Output sent to client No. " + clNo); messageDisplay.displayOutgoingText(outputMessage); } catch (System.IO.IOException ex) { // expected time out } catch (Exception ex) { Console.WriteLine(" >> " + ex.ToString()); running = false; } } clientSocket.Close(); }
private void doChat() { int requestCount = 0; int buffSize = 10 * 1024; byte[] bytesFrom = new byte[buffSize]; string dataFromClient = null; Byte[] sendBytes = null; string serverResponse = null; string rCount = null; requestCount = 0; NetworkStream networkStream = clientSocket.GetStream(); networkStream.ReadTimeout = 50; serverResponse = "ACK:(" + clNo + ")." + rCount + "\0"; sendBytes = Encoding.ASCII.GetBytes(serverResponse); networkStream.Write(sendBytes, 0, sendBytes.Length); networkStream.Flush(); //var engine = new Engine().SetValue("log", new Action<object>(getString)); var engine = new Engine(cfg => cfg.AllowClr()); engine.SetValue("log", new Action<object>(getString)); engine.SetValue("Color", new System.Drawing.Color()); indy ui = new indy(); engine.SetValue("ui", ui); running = true; while (running) { try { requestCount = requestCount + 1; networkStream.Read(bytesFrom, 0, bytesFrom.Length); dataFromClient = Encoding.ASCII.GetString(bytesFrom); dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf('\0')); messageDisplay.displayStatusText("Received code from client No. " + clNo); rCount = Convert.ToString(requestCount); outputMessage = "ok_tx\n"; try { engine.Execute(dataFromClient); } catch (Exception e) { outputMessage = e.ToString(); } sendBytes = Encoding.ASCII.GetBytes(outputMessage); networkStream.Write(sendBytes, 0, sendBytes.Length); messageDisplay.displayStatusText("Output sent to client No. " + clNo); messageDisplay.displayOutgoingText(outputMessage); } catch (System.IO.IOException ex) { // expected time out } catch (Exception ex) { Console.WriteLine(" >> " + ex.ToString()); running = false; } } clientSocket.Close(); }