I'm trying to create a socket polling server (well that's the first step anyway - end goal is a reverse proxy server).
Anyway, I'm fairly useless with C#, but I can't seem to get it to bind a port to a listening socket... It throws an exception every time I run it on the listenSock.bind(endPoint) call:
Code:System.Net.Sockets.SocketException: An invalid argument was supplied at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at Proxy.Form1..ctor() in Blah:\Form1.cs: line 27Can anyone let me know what I'm doing wrong? :/ I've done some Google searches and from the Google hits it appears I'm doing it correctly.Code:List<Socket> connectedClients = new List<Socket>(); public Form1() { InitializeComponent(); IPAddress addr = IPAddress.Parse("127.0.0.1"); IPEndPoint endPoint = new IPEndPoint(addr, Globals.port); Socket listenSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); while (true) { try { listenSock.Bind(endPoint); } catch (Exception e) { MessageBox.Show(e.ToString()); } listenSock.Listen(10); if (listenSock.Poll(0, SelectMode.SelectRead)) connectedClients.Add(listenSock.Accept()); foreach (Socket sock in connectedClients) { if (sock.Poll(0, SelectMode.SelectError)) connectedClients.Remove(sock); else if (sock.Poll(0, SelectMode.SelectRead)) // placeholder ParserFunction(sock); } }
Thanks!



LinkBack URL
About LinkBacks


