Reputation: 59
I'm now using a socket server in C# but I can only bind it to 127.0.0.1. But it has to bind to my VPS IP. Even if I try to bind to my hamachi IP, it doesn't work.
I use:
ServerSocketSettings Settings = new ServerSocketSettings
{
MaxConnections = Config.ServerMaxConnections,
NumOfSaeaForRec = Config.ServerMaxConnections,
Backlog = 30,
MaxSimultaneousAcceptOps = 15,
BufferSize = 512,
Endpoint = new IPEndPoint(IPAddress.Parse("25.168.77.190"), Config.ServerPort)
};
this._serverSocket = new ServerSocket(Settings);
Then I do:
this.ListenSocket = new Socket(this.Settings.Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
this.ListenSocket.Bind(this.Settings.Endpoint);
this.ListenSocket.Listen(this.Settings.Backlog);
the this.Settings is the value of the code above. When I run it, I get:
The requested address is not valid in its context
I'm wondering why it doesn't work.
Upvotes: 4
Views: 1355
Reputation: 1730
You should bind the Listening Socket only to a specific Interface if you want to limit the availability of the service to this network segment.
If this is not needed you can just bind it to any ip address with
this.ListenSocket.Bind(new IPEndPoint(IPAddress.Any));
Upvotes: 1