Can only bind a socket to 127.0.0.1

Now I am using a socket server in C #, but I can only bind it to 127.0.0.1. But he has to contact my VPS IP. Even if I try to bind my Hamachi IP address, it does not 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);

this.Settings is the value of the above code. When I run it, I get:

The requested address is invalid in its context

I am wondering why this is not working.

+4
source share
1 answer

You should only bind the Listening Socket to a specific interface if you want to limit the availability of services for this network segment.

If this is not needed, you can simply bind it to any ip address with

this.ListenSocket.Bind(new IPEndPoint(IPAddress.Any));
+1
source

All Articles