Now I encounter a problem with a thorny hand, that's it!
My client needs to communicate with the server through socket, but the client server has dual IP addresses (for example, 192.168.1.10 and 192.168.1.20). However, the server only allows 192.168.1.20 to communicate, and has ip restrictions. On the client, 192.168.1.10 is the main IP, and 192.168.1.20 is the slave IP. If I simply establish a connection through socket, the program will communicate with 192.168.1.10 by default, so the server will refuse. Should I solve this problem if I write it?
Don't manually, it must be implemented automatically by the program, and you can bind any local IP address.
If the IP address of the machine is:
192.168.1.205,192.168.1.204,192.168.1.203
The result is:
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.205:2302 59.39.71.94:80 ESTABLISHED
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.203:12302 59.39.71.94:80 ESTABLISHED
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.204:7802 59.39.71.94:80 ESTABLISHED
If it is convenient, give me a code! Thanks!
Code highlighting produced by Actipro CodeHighlighter (freeware)/--> 1 string serverIp = "59.39.71.94";
int serverProt = 80;
string clientIp = "192.168.1.104";
int clientProt = 8012;
var socket = new Socket(, , );
var ipHostEntry = (serverIp);
var ipEndPoint = new IPEndPoint([0], serverProt);
var address = (clientIp);
if (address != null)
{
var localEp = new IPEndPoint(address, clientProt);
(localEp);
}
(ipEndPoint); //Create a long connection
The above code can fully implement the above functions.
My client needs to communicate with the server through socket, but the client server has dual IP addresses (for example, 192.168.1.10 and 192.168.1.20). However, the server only allows 192.168.1.20 to communicate, and has ip restrictions. On the client, 192.168.1.10 is the main IP, and 192.168.1.20 is the slave IP. If I simply establish a connection through socket, the program will communicate with 192.168.1.10 by default, so the server will refuse. Should I solve this problem if I write it?
Don't manually, it must be implemented automatically by the program, and you can bind any local IP address.
If the IP address of the machine is:
192.168.1.205,192.168.1.204,192.168.1.203
The result is:
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.205:2302 59.39.71.94:80 ESTABLISHED
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.203:12302 59.39.71.94:80 ESTABLISHED
C:\>netstat -an | find "59.39.71.94"
TCP 192.168.1.204:7802 59.39.71.94:80 ESTABLISHED
If it is convenient, give me a code! Thanks!
Copy the codeThe code is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)/--> 1 string serverIp = "59.39.71.94";
int serverProt = 80;
string clientIp = "192.168.1.104";
int clientProt = 8012;
var socket = new Socket(, , );
var ipHostEntry = (serverIp);
var ipEndPoint = new IPEndPoint([0], serverProt);
var address = (clientIp);
if (address != null)
{
var localEp = new IPEndPoint(address, clientProt);
(localEp);
}
(ipEndPoint); //Create a long connection
The above code can fully implement the above functions.