private static void onConnected(ZitiConnection connection, ZitiStatus status) { ZitiUtil.CheckStatus(status); string cfg = connection.Service.GetConfiguration("weather-config-type"); string where = null; if (cfg == null) { where = "London"; Console.WriteLine("The service does not have a configuration of type 'weather-config-type' - using default: " + where); } else { where = JsonDocument.Parse(cfg).RootElement.GetProperty("where").ToString(); } byte[] bytes = Encoding.UTF8.GetBytes($"GET /{where} HTTP/1.0\r\n" + "Accept: *-/*\r\n" + "Connection: close\r\n" + "User-Agent: curl/7.59.0\r\n" + "Host: wttr.in\r\n" + "\r\n"); connection.Write(bytes, afterDataWritten, "write context"); }
private static void onClientAccept(ZitiConnection clientConnection, ZitiStatus status) { ZitiUtil.CheckStatus(status); string msg = "Hello from byte counter!"; clientConnection.Write(Encoding.UTF8.GetBytes(msg), msg.Length, afterDataWritten, ZitiUtil.NO_CONTEXT); }
private static void onConnected(ZitiConnection connection, ZitiStatus status) { ZitiUtil.CheckStatus(status); Console.WriteLine("sending HTTP request: " + connection.ConnectionContext); string payload = @"GET / HTTP/1.0 Host: eth0.me User-Agent: curl/7.55.1 Accept: */* "; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(payload); connection.Write(bytes, afterDataWritten, "write context"); }
private static void afterDataWritten(ZitiConnection connection, ZitiStatus status, object context) { ZitiUtil.CheckStatus(status); }