/// <summary> /// Writes the given string to the socket after UTF-8 encoding. /// </summary> /// <param name="str">String to write out.</param> public override void Write(string str) { int keep = (int)m_listener[Options.CURRENT_KEEP_ALIVE]; if (keep > 0) { m_timer.Change(keep, keep); } m_sock.Write(ENC.GetBytes(str)); }
public bool OnRead(BaseSocket sock, byte[] buf, int offset, int length) { string str = ENC.GetString(buf, offset, length); Console.WriteLine("SR: " + str); if (str.Contains("11111")) { sock.Write(ENC.GetBytes(@"HTTP/1.1 200 OK Content-Length: 10 Content-Type: text/plain 1234567890")); } else if (str.Contains("22222")) { sock.Write(ENC.GetBytes(@"HTTP/1.1 200 OK Content-Length: 10 Content-Type: text/plain 12345")); sock.Write(ENC.GetBytes("67890")); } else if (str.Contains("33333")) { sock.Write(ENC.GetBytes(@"HTTP/1.1 200 OK Content-Length: 20 Content-Type: text/plain 12345")); // Turning off Nagle didn't fix this. Mrmph. Thread.Sleep(300); sock.Write(ENC.GetBytes("67890")); Thread.Sleep(300); sock.Write(ENC.GetBytes("12345")); Thread.Sleep(300); sock.Write(ENC.GetBytes("67890")); } return(true); }
/// <summary> /// Writes a string to the stream. /// </summary> /// <param name="str"> /// The string to write; this will be transcoded to UTF-8. /// </param> public override void Write(string str) { //int keep = (int)m_listener[Options.KEEP_ALIVE]; m_sock.Write(ENC.GetBytes(str)); }
public void OnConnect(BaseSocket sock) { sock.Write(sbuf, 5, 10); }