/// <summary> /// This will wait for the SensorNetworkServer, and when it finds it, it will connect! /// This code was directly lifted from how this functionality works in the Teensy's source code. /// </summary> private void WaitForAndConnectToServer() { bool connected = false; // Wait for the SensorNetworkServer to be up while (!connected && CurrentlyRunning) { try { Client = new TcpClient(ClientIP, ClientPort); ClientStream = Client.GetStream(); connected = true; // Ask the SensorNetworkServer for its initialization byte[] askForInit = Encoding.ASCII.GetBytes("Send Sensor Configuration"); ClientStream.Write(askForInit, 0, askForInit.Length); ClientStream.Flush(); } catch { logger.Info($"{Utilities.GetTimeStamp()}: SimulationSensorNetwork is waiting for the SensorNetworkServer."); if (Client != null) { Client.Dispose(); } if (ClientStream != null) { ClientStream.Dispose(); } } } }
public void RespondBlockPage() { String bp = "<html><body>Block Page</body></html>"; SendHeader("", bp.Length, "404"); SendBlockPage(bp); ClientStream.Flush(); ClientStream.Close(); }
private void SendMessage() { if (string.IsNullOrWhiteSpace(MessageBox)) { return; } ClientStream.Write(Encoding.UTF8.GetBytes(MessageBox.Trim())); ClientStream.Flush(); MessageBox = string.Empty; }
public void RespondToRequest() { string fpath = ""; string mimetype = ""; if (localPath != null) { fpath = wbmap.GetPath(localPath); mimetype = wbmap.GetMime(localPath); } if (fpath != "" && mimetype != "") { String retstring = ""; if (mimetypeAscii(mimetype) == true) { if (GetFileStream(fpath, out retstring) == true) { SendHeader(mimetype, retstring.Length, "200"); SendBody(retstring); ClientStream.Flush(); ClientStream.Close(); } else { RespondBlockPage(); } } else { byte[] bout = null; if (GetBinaryFile(fpath, out bout) == true) { SendHeader(mimetype, bout.Length, "200"); SendBodyBinary(bout); ClientStream.Flush(); ClientStream.Close(); } else { RespondBlockPage(); } } } else { RespondBlockPage(); } }
public override void SendData(byte[] data) { ClientStream.Write(data, 0, data.Length); ClientStream.Flush(); }