static void Main(string[] args) { try { Console.WriteLine("Server is running..."); MyWebServer webServer = new MyWebServer("http://127.0.0.1", "8084"); webServer.Configure <Configurator>().Run(); } catch (Exception ex) { Console.WriteLine("Server stoped"); Console.WriteLine(ex.Message); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.Browser = new CefSharp.Wpf.ChromiumWebBrowser(); //browser.Address = @"http://147zxcv.xiaopangkj.space/player.html"; //this.WebBrowser.WebBrowser.Do // 注意,第二个路径不要加 "/" // 错误:@"/Res/index.html" IPAddress iPAddress = IPAddress.Any; IPEndPoint iPEndPoint = new IPEndPoint(iPAddress, 5893); MyWebServer webServer = new MyWebServer(iPEndPoint); webServer.Start(); this.Browser.Address = @"http://127.0.0.1:5893/player.html"; this.Content = this.Browser; }
public static void Main() { off(); // primero nos aseguramos de que este todo apagado MyWebServer server = new MyWebServer(); I2CDevice sensor = new I2CDevice(new I2CDevice.Configuration(0x48, 50)); server.Start();// Lanzamos el servidor Thread LecturaTemperatura = new Thread(readTemp); LecturaTemperatura.Start();// mostamos el LCD los datos correspondientes TimeController timecontroller = new TimeController(); bool configured; string errorMessage = null; configured = timecontroller.Configure(Datos.rangos, 100000, 500, out errorMessage); }
static void Main(string[] args) { try { MyWebServer MWS = new MyWebServer(); TcpClient client = new TcpClient(chromecast_server, 8009); SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); string data = null; string response = null; string sessionId = null; string transportId = null; //string[] response = new string[20]; //int respCount = 0; //sslStream.AuthenticateAsClient(""); sslStream.AuthenticateAsClient(chromecast_server, null, SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Default, false); sslStream.ReadTimeout = 100000; sslStream.WriteTimeout = 100000; // This is where you read and send data Console.WriteLine("connecting..."); /* test code * sessionId = "b6ec8bf8-e1a4-418d-88b6-8fe2b51ac057"; * transportId = "7cde1d99-aef8-44dc-a9f9-5d2050fc5594"; * * data = "{\"type\":\"LOAD\",\"requestId\":46479002,\"sessionId\":\"" + sessionId + "\",\"media\":{\"contentId\":\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\",\"streamType\":\"buffered\",\"contentType\":\"video/mp4\"},\"autoplay\":true,\"currentTime\":0,\"customData\":{\"payload\":{\"title:\":\"Big Buck Bunny\",\"thumb\":\"images/BigBuckBunny.jpg\"}}}"; * chrome_namespace = "urn:x-cast:com.google.cast.media"; * CreateRequest(sslStream, data, transportId); * // end of test code */ // connect data = "{\"type\":\"CONNECT\",\"origin\":{}}"; chrome_namespace = "urn:x-cast:com.google.cast.tp.connection"; CreateRequest(sslStream, data); // get status data = "{\"type\":\"GET_STATUS\",\"requestId\":46479000}"; chrome_namespace = "urn:x-cast:com.google.cast.receiver"; CreateRequest(sslStream, data); /* Try the following test code when connectiing to my SSL test server * data = "Hello from the client.<EOF>"; * byte [] buffer = new byte[2048]; * Encoding.ASCII.GetBytes(data, 0, data.Length, buffer, 0); * sslStream.Write(buffer, 0, data.Length); */ while (sessionId == null) { if (ReadMessage(sslStream, ref response) == false) { return; } if (response != null) { Console.WriteLine("response: " + response); var jObject = JObject.Parse(response); if (jObject["status"] != null) { if (jObject["status"]["applications"][0]["sessionId"] != null) { sessionId = jObject["status"]["applications"][0]["sessionId"].ToString(); break; } } } } Console.WriteLine("session = " + sessionId); // PONG data = "{\"type\":\"PING\"}"; chrome_namespace = "urn:x-cast:com.google.cast.tp.heartbeat"; CreateRequest(sslStream, data); //launch data = "{\"type\":\"LAUNCH\",\"requestId\":46479001,\"appId\":\"CC1AD845\"}"; // CACD78FE is my receiver //data = "{\"type\":\"LAUNCH\",\"requestId\":46479001,\"appId\":\"CACD78FE\"}"; chrome_namespace = "urn:x-cast:com.google.cast.receiver"; CreateRequest(sslStream, data); while (transportId == null) { if (ReadMessage(sslStream, ref response) == false) { return; } if (response != null) { Console.WriteLine("response: " + response); var jObject = JObject.Parse(response); if (jObject["status"] != null) { if (jObject["status"]["applications"] != null) { if (jObject["status"]["applications"][0]["transportId"] != null) { transportId = jObject["status"]["applications"][0]["transportId"].ToString(); break; } } } } } Console.WriteLine("transportId= " + transportId); // PING AGAIN data = "{\"type\":\"PING\"}"; chrome_namespace = "urn:x-cast:com.google.cast.tp.heartbeat"; CreateRequest(sslStream, data); // connect to new destination data = "{\"type\":\"CONNECT\",\"origin\":{}}"; chrome_namespace = "urn:x-cast:com.google.cast.tp.connection"; CreateRequest(sslStream, data, transportId); // load data = "{\"type\":\"LOAD\",\"requestId\":46479002,\"sessionId\":\"" + sessionId + "\",\"media\":{\"contentId\":\"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4\",\"streamType\":\"buffered\",\"contentType\":\"video/mp4\"},\"autoplay\":true,\"currentTime\":0,\"customData\":{\"payload\":{\"title:\":\"Big Buck Bunny\",\"thumb\":\"images/BigBuckBunny.jpg\"}}}"; //data = "{\"type\":\"LOAD\",\"requestId\":46479002,\"sessionId\":\"" + sessionId + "\",\"media\":{\"contentId\":\"http://localhost:5050/0\",\"streamType\":\"buffered\",\"contentType\":\"video/mp4\"},\"autoplay\":true,\"currentTime\":0,\"customData\":{\"payload\":{\"title:\":\"Big Buck Bunny\",\"thumb\":\"images/BigBuckBunny.jpg\"}}}"; //data = "{\"type\":\"LOAD\",\"autoplay\":true,\"currentTime\":0,\"activeTrackIds\":[],\"media\":{\"contentId\":\"http://192.168.1.4/ED_1280.mp4\",\"contentType\":\"video/mp4\",\"streamType\":\"BUFFERED\",\"metadata\":{\"filePath\":\"d:\\vantage_store\\ED_1280.mp4\",\"title\":\"ED_1280.mp4\"}},\"requestId\"::46479002}"; // home //data = "{\"type\":\"LOAD\",\"requestId\":46479002,\"sessionId\":\"" + sessionId + "\",\"media\":{\"contentId\":\"http://192.168.1.4/sourcempeg2_422_pro_ntsc.mp4\",\"streamType\":\"buffered\",\"contentType\":\"video/mp4\"},\"autoplay\":true,\"currentTime\":0,\"customData\":{\"payload\":{\"title:\":\"Big Buck Bunny\",\"thumb\":\"images/BigBuckBunny.jpg\"}}}"; /// office //data = "{\"type\":\"LOAD\",\"requestId\":46479002,\"sessionId\":\"" + sessionId + "\",\"media\":{\"contentId\":\"http://10.0.19.219/sourcempeg2_422_pro_ntsc.mp4\",\"streamType\":\"buffered\",\"contentType\":\"video/mp4\"},\"autoplay\":true,\"currentTime\":0,\"customData\":{\"payload\":{\"title:\":\"Big Buck Bunny\",\"thumb\":\"images/BigBuckBunny.jpg\"}}}"; chrome_namespace = "urn:x-cast:com.google.cast.media"; CreateRequest(sslStream, data, transportId); bool exitFlag = false; while (!exitFlag) { if (ReadMessage(sslStream, ref response) == false) { return; } Console.WriteLine("response: " + response); if (response.Contains("idleReason")) { Console.WriteLine("Finished"); exitFlag = true; } // PING AGAIN data = "{\"type\":\"PING\"}"; chrome_namespace = "urn:x-cast:com.google.cast.tp.heartbeat"; CreateRequest(sslStream, data); System.Threading.Thread.Sleep(500); } client.Close(); } catch (System.Security.Authentication.AuthenticationException e) { Console.WriteLine("Exception: {0}", e.Message); if (e.InnerException != null) { Console.WriteLine("Inner exception: {0}", e.InnerException.Message); } Console.WriteLine("Authentication failed - closing the connection."); } catch (Exception e) { Console.WriteLine("failed - closing the connection."); } }
// Application Starts Here.. public static void Main() { MyWebServer MWS = new MyWebServer(); }