Tcplistener: Objhttp Setrequestheader
Tcplistener: Objhttp Setrequestheader
0;
Windows NT 5.0)"
tcplistener
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
class MyTcpListener
{
public static void Main()
{
TcpListener server=null;
try
{
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
data = null;
int i;
// Loop to receive all the data sent by the client.
while((i = stream.Read(bytes, 0, bytes.Length))!=0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("Received: {0}", data);
if (new Regex("^GET").IsMatch(data)) {
Byte[] response = Encoding.UTF8.GetBytes("HTTP/1.1 101
Switching Protocols" + Environment.NewLine
+ "Connection: Upgrade" + Environment.NewLine
+ "Upgrade: websocket" + Environment.NewLine
+ "Sec-WebSocket-Accept: " + Convert.ToBase64String (
SHA1.Create().ComputeHash (
Encoding.UTF8.GetBytes (
new Regex("Sec-WebSocket-Key:
(.*)").Match(data).Groups[1].Value.Trim() + "258EAFA5-E914-47DA-
95CA-C5AB0DC85B11"
)
)
) + Environment.NewLine
+ Environment.NewLine);
stream.Write(response, 0, response.Length);
}
this.FormBorderStyle = FormBorderStyle.None;
ControlBox = False