public void Connect(IPAddress ip, int port, bool useUdp) { IPEndPoint ipep = new IPEndPoint(ip, port); if (!useUdp) { Socket s = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.IP); s.Connect(ipep); MemoryStream ms = new MemoryStream(); Bencode.write("hello", ms); s.Send(ms.ToArray(), SocketFlags.None); } }
public void Create() { IPEndPoint ipep = new IPEndPoint(ip, port); Socket s = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.IP); s.Bind(ipep); s.Listen(-1); Socket client = s.Accept(); MemoryStream ms = new MemoryStream(); Dictionary <string, object> helloMsg = new Dictionary <string, object>(); helloMsg.Add("ver", 1); helloMsg.Add("token", "mi"); Bencode.write(helloMsg, ms); }