public async Task Connect() { sock = SocketHelper.GetSocket(); await SocketHelper.ConnectAsync(sock, remote); local = (IPEndPoint)sock.LocalEndPoint; }
private async void AcceptConnection(Socket sli) { var sock = await SocketHelper.AcceptAsync(sli); AcceptConnection(sli); SocketHelper.ConnectAndHandle(sock, handler); }
public async Task ParseInput() { var tc = new TcpClient(new IPEndPoint(Dns.GetHostAddresses("www.facebook.com")[0], 80)); await tc.Connect(); //await buf.Write(Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\nConnection: Closed\r\n\r\nHello, World!")); //buf.FinishWrite(); tc.Handle(async aw => { for (;;) { var bl = await ReadLine(); var l = Encoding.ASCII.GetString(bl); if (l.StartsWith("Host: ")) { bl = Encoding.ASCII.GetBytes("Host: www.facebook.com:80"); } await aw.Write(bl); await aw.Write(Encoding.ASCII.GetBytes("\r\n")); if (l.Length == 0) { break; } } SocketHelper.RelayHandler(buf, aw); }); }
public void Start() { sli = SocketHelper.GetSocket(); sli.Bind(new IPEndPoint(IPAddress.Any, port)); sli.Listen(5); for (var i = 0; i < 5; ++i) { AcceptConnection(sli); } Dispatcher.Run(); }
private async Task ConnectCommand(IPEndPoint ep) { var tc = new TcpClient(ep); await tc.Connect(); var buf = new byte[10]; Array.Copy(new byte[] { 0x5, 0, 0, 0x1 }, buf, 4); Array.Copy(tc.Source.GetAddressBytes(), 0, buf, 4, 4); buf[8] = (byte)(tc.Port >> 8); buf[9] = (byte)(tc.Port & 0xff); await readWrite.Write(buf); tc.Handle(rw => SocketHelper.RelayHandler(readWrite, rw)); }
public void Handle(Action <IAsyncReadWrite> handler) { SocketHelper.ConnectAndHandle(sock, handler); }