I am currently creating a TCP server application with the following configuration:
PC (client)<--Internet-->Load balancer-----------Server1
-- --------------------------- Server 2
-- --------------------------- Server 3
The server application uses the .NET Framework Socket
class.
The parameters specified for the socket class are
AddressFamily#InterNetwork
SocketType#Stream
ProtocolType#Tcp
When generating an instance, you set the above (TCP transmit and receive settings).
The environment is also as follows:
The following code was supposed to be able to get the IP address of the connected client, but the IP address of the load balancer is obtained.
The following is a pseudo code
Socket ClientSocket=ServerSocket.EndAccept(iAsyncResult);
String IpAddress=(IPEndPoint)ClientSocket.RemoteEndPoint).Address.ToString();
Console.WriteLine (IpAddress);
--------------
output:load balancer IP address
--------------
After monitoring and investigating packets using WireShark, we found that the IP header contained the IP address of the client PC.Perhaps it's a bad way to get it from the program, but I don't know how to get the IP address listed in the IP header.
I would appreciate it if you could let me know if you have any tips.
windows .net socket
Possible
That's about it (out of order).
There was a similar question in the English version, but there was an answer asking if it was proxy.
Socket.RemoteEndPoint returns gateway address
In some cases, it overlaps with the comments, but in general, list the items and methods you would like to review.
Trace information output can be set to enabled to trace Socket.
System.Net.Sockets Information:0:[4292] Socket#45653674-192.168.1.2:58849 to 192.168.1.1:22222.
C:\>netstat-n
Active Connections
Protocol Local Address External Address State
TCP 127.0.0.1:2222127.0.0.1:51819 ESTABLISHED
TCP 192.168.1.1:2222192.168.1.2:58849 ESTABLISHED
In this example, there are two connections to the server port (22222), although unnecessary parts are omitted.
Is the client-server connection displayed correctly?Also, are there no load balancer server connections?
Obtain and verify packets with a network analyzer such as Wireshark.
One thing to be aware of at this time is to pay attention to other than "packet as you intend."
In this example, a packet destined for a PC-server is a "intended packet", but does the packet actually have no connection or other communication between the load balancer and the server?
The load balancer translates client or server addresses by (design) configuration.See what the settings are.
Also, if you are performing a health check, the load balancer connects to the server.This may cause unintended errors.(e.g. socket is filled)
Since I use Socket instead of WebRequest, I wonder if it's a non-HTTP protocol, but if it's HTTP, I'll put an X-Forwarded-For header in the HTTP header when BIG-IP changes addresses.
http://ja.wikipedia.org/wiki/X-Forwarded-For
If the HTTP header contains information, you can retrieve it from the WebRequest.Headers property.(I didn't try...)
© 2024 OneMinuteCode. All rights reserved.