예제 #1
0
        /// <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();
                    }
                }
            }
        }
예제 #2
0
        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;
 }
예제 #4
0
        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();
            }
        }
예제 #5
0
 public override void SendData(byte[] data)
 {
     ClientStream.Write(data, 0, data.Length);
     ClientStream.Flush();
 }