using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; namespace udptest { class Program { private static Socket Sock; private static string ip = ""; static void Main(string[] args) { Console.WriteLine("daj ip"); ip = Console.ReadLine(); Sock = new Socket(IPAddress.Any.AddressFamily, SocketType.Dgram, ProtocolType.Udp); Sock.Bind(new IPEndPoint(IPAddress.Any, 4000)); Thread t = new Thread(new ThreadStart(receive)); t.IsBackground = true; t.Start(); Console.WriteLine("nacisnij enter aby wywiercic dziure"); Console.ReadLine(); Sock.SendTo(Encoding.ASCII.GetBytes("HOLE PUNCH"), new IPEndPoint(IPAddress.Parse(ip), 4000)); while (true) { Sock.SendTo(Encoding.ASCII.GetBytes(Console.ReadLine()), new IPEndPoint(IPAddress.Parse(ip), 4000)); } } private static void receive() { while (true) { byte[] buff = new byte[4096]; EndPoint ep = new IPEndPoint(IPAddress.Any, 4000); int len = Sock.ReceiveFrom(buff, ref ep); Console.WriteLine("recv from " + ep.ToString() + " : " + Encoding.ASCII.GetString(buff, 0, len)); } } } }