How to fix the local port in a TCP Client connection instead of a random port?

pinosx
Posts: 1
Joined: Sat May 18, 2019 11:19 am

How to fix the local port in a TCP Client connection instead of a random port?

Postby pinosx » Sat May 18, 2019 11:43 am

Hello, friends,
I have a question:
Is it possible to fix a local port during the TCP Client connection on ESP32 (Arduino IDE)?

My device must connect to a TCP server at a certain port, and this step is done without any problems using it:

Code: Select all

WiFiClient client;
if (!client.connect(host, port)) {
	....
	return;
}
Unfortunately the local port changes with each connection and I have problems with the network policies set by the IT department that have opened only one port (11001) and I have to be able to use only that!

Attached a screenshot taken from the server side where you can see that the remote port (local for esp32) changes dynamically.

maybe this methods of the class 'WiFiClient' can help me? but I can't find any documentation about it:

Code: Select all

    int setSocketOption(int option, char* value, size_t len);
    int setOption(int option, int *value);
ps. using Python on a different device I can fix the local port

thank you all for your help,
Pino
Attachments
gui_udp_localport.png
gui_udp_localport.png (46.92 KiB) Viewed 3983 times

Mautoz
Posts: 1
Joined: Wed Nov 10, 2021 12:37 am

Re: How to fix the local port in a TCP Client connection instead of a random port?

Postby Mautoz » Wed Nov 10, 2021 12:40 am

WiFiClient client;
client.setLocalPortStart(55052);

Who is online

Users browsing this forum: No registered users and 57 guests