public override async Task <bool> SendAsync(CommContext context) { var cmdStr = context.Command.Build(); await _client.SendAsync(cmdStr).ConfigureAwait(false); context.SendTime = DateTime.Now; _history.OnNext(context); return(await Task.FromResult(true).ConfigureAwait(false)); }
public void SendAsync(byte[] data) { if (data != null) { _Client.SendAsync(data).Wait(); } }
static void Connected(object sender, EventArgs e) { client.SendAsync("{\"op\":\"connect\",\"username\":\"" + theForm.username.Text + "\"}"); theForm.label5.Text = "up"; theForm.label5.ForeColor = System.Drawing.Color.Green; }
static void SendAsync() { string data = InputString("Data:", "Hello!", true); if (!String.IsNullOrEmpty(data)) { _Client.SendAsync(data).Wait(); } }
private async void Listener_OnConnectionAccepted(object sender, NewConnectionArgs e) { Console.WriteLine("[TCPServer] New client connected"); SimpleTcpClient newClient = new SimpleTcpClient(1024, e.Client); newClient.OnException += NewClient_OnException; newClient.OnReceivedMessage += NewClient_OnReceivedMessage; newClient.Start(); await newClient.SendAsync(Encoding.ASCII.GetBytes("Hello I'm your server :D")); connectedClients.Add(newClient); }
public async void Send(string msg) { await client.SendAsync(Encoding.ASCII.GetBytes(msg)); }
/// <summary> /// Handles http requests and sends a response /// </summary> /// <param name="client">Tcp client</param> /// <param name="info">Request info</param> private async void HandleRequest(SimpleTcpClient client, RequestInfo info) { if (info.Methode == MethodeType.GET) { string fullPath = rootFullPath + info.Content; if (File.Exists(fullPath)) { string type = Mapper.GetContentType(Path.GetExtension(fullPath)); DateTime modifiedTime = File.GetLastWriteTime(fullPath); string encoding = null; string charset = null; byte[] content = null; if (type.StartsWith("text")) //text encoding { string data; if (Path.GetExtension(fullPath) == ".cs") { data = ExecuteScript(fullPath); } else { data = File.ReadAllText(fullPath); } content = Encoding.GetEncoding(config.DefaultCharset).GetBytes(data); encoding = null; charset = config.DefaultCharset; } else //byte encoding { if (info.Encoding.HasFlag(EncodingType.GZIP)) { content = Compressions.GZip(File.ReadAllBytes(fullPath)); encoding = "gzip"; } else if (info.Encoding.HasFlag(EncodingType.DEFLATE)) { content = Compressions.Deflate(File.ReadAllBytes(fullPath)); encoding = "deflate"; } else { content = File.ReadAllBytes(fullPath); } } int fullLength = content.Length; content = DoRangeManipulation(content, info.StartRange, info.EndRange); ResponseInfo response = new ResponseInfo("1.1", "200", "OK", modifiedTime.ToString(), null, type, content, info.KeepAlive, charset, encoding); await client.SendAsync(response.CreateResponse(lf, fullLength, info.StartRange, info.EndRange)); } else { await client.SendAsync(GetErrorResponse(404).CreateResponse(lf)); //file not found (404) } } else { await client.SendAsync(GetErrorResponse(405).CreateResponse(lf)); //Unsupported methode } if (!info.KeepAlive) { client.Stop(); } }