コード例 #1
0
ファイル: HttpSocketTest.cs プロジェクト: krbysn/jabber-net
            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;
            }
コード例 #2
0
 /// <summary>
 /// Async write to the socket.  Listener.OnWrite will be called eventually
 /// when the data has been written.  A trimmed copy is made of the data, internally.
 /// </summary>
 /// <param name="buf">Buffer to output</param>
 /// <param name="offset">Offset into buffer</param>
 /// <param name="len">Number of bytes to output</param>
 public override void Write(byte[] buf, int offset, int len)
 {
     m_sock.Write(buf, offset, len);
 }
コード例 #3
0
 public void OnConnect(BaseSocket sock)
 {
     sock.Write(sbuf, 5, 10);
 }