Simple TCP communication over wifi

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Simple TCP communication over wifi

Postby kolban » Fri Jul 13, 2018 2:28 pm

What is the nature of the program listening on the socket on Windows?
Can you ping the ESP32 from Windows?
What source statement is the error being logged at on the ESP32?
Is the message being issued from the ESP32 or the windows app?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Simple TCP communication over wifi

Postby Deouss » Fri Jul 13, 2018 3:06 pm

From monitor:

I (3666) tcp client: ESP32 Connected to WiFi ! Start TCP Socket....
E (5676) tcp client: connect to server failed! errno=104

Console program is listening for connection on port and is supposed to read some data from esp in form of string
ESP connects fine to WiFi and fails when tries to connect the socket

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Simple TCP communication over wifi

Postby fly135 » Fri Jul 13, 2018 4:24 pm

Deouss wrote:From monitor:

I (3666) tcp client: ESP32 Connected to WiFi ! Start TCP Socket....
E (5676) tcp client: connect to server failed! errno=104

Console program is listening for connection on port and is supposed to read some data from esp in form of string
ESP connects fine to WiFi and fails when tries to connect the socket
Clearly you are doing something wrong. If you intend to post so little detail, I'd suggest you get a cheap managed switch, plug your wifi router into it, put a computer on one of the wired ports, and port mirror the wifi port to the computer port. Then you can use wireshark to see what the TCP packets have to say about it. Maybe the port you assigned is reverse endian and the windows computer isn't listening to it.

John A

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Simple TCP communication over wifi

Postby Deouss » Fri Jul 13, 2018 4:38 pm

Could be..I will try also bluetooth - wonder if it is also tcp-like protocol

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Simple TCP communication over wifi

Postby fly135 » Fri Jul 13, 2018 4:57 pm

Deouss wrote:Could be..I will try also bluetooth - wonder if it is also tcp-like protocol
I think you should stick with TCP and figure it out. There is no reason that what you are trying to do shouldn't work other than obvious mistakes. Switching to Bt isn't really the issue. My less than subtle point was that you can't get any help with your problem if you don't post more info about your code. For example, we don't even know if you have gotten an IP address on the ESP32 before you try to connect to the PC. If you plan to work with IP protocol on a regular basis then the ability to use wireshark to debug problems is a big asset.

The best way to get help on an issue is to post as much info as possible. A log with logging set to verbose is usually needed.

How about htons and htonl? Do you know what those do? For example here is some code trying to connect to telnet port 23?

Code: Select all

sock_info.sin_port = htons(23);
You might be trying to connect on the wrong port. Without the htons, it would be trying to connect to port 5888.

John A

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Simple TCP communication over wifi

Postby Deouss » Fri Jul 13, 2018 6:38 pm

Your terminal application does not support escape sequences.
Line editing and history features are disabled.
On Windows, try using Putty instead.
esp32> sta PublicWifi
I (9315) iperf: sta connecting to 'PublicWifi'
I (13667) event: sta ip: 192.168.13.90, mask: 255.255.248.0, gw: 192.168.8.1
esp32> iperf -c10.150.8.53 -p3855
I (63770) iperf: mode=tcp-client sip=192.168.13.90:5001, dip=10.150.8.53:3855, interval=3, time=30
esp32> W (82022) iperf: tcp client connect error, error code: 113, reason: Software caused connection abort
I (82023) iperf: iperf exit
I (340756) iperf: sta disconnect, reconnect...
I (345165) event: sta ip: 192.168.13.90, mask: 255.255.248.0, gw: 192.168.8.1
C# console
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 3855); //0x0F0F to be safe
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEndPoint);
listener.Listen(10);
listener.Accept();

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Simple TCP communication over wifi

Postby kolban » Fri Jul 13, 2018 6:46 pm

Maybe try an eliminate as many unknowns as possible. Perhaps try running PacketSender on Windows ... see:

https://packetsender.com/

This can be configured to be a Socket listener and display incoming socket traffic. This way there is less ambiguity in there possible being something amiss in the socket server side.

If that still fails, then you could create the smallest ESP32 application possible that leverages sockets and post that as a pastebin and maybe we can take a look.

Also, what you think the IP address of your ESP32 is and what do you think the IP of your Windows PC is?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Simple TCP communication over wifi

Postby Deouss » Fri Jul 13, 2018 8:16 pm

I RESOLVED IT ))

Windows socket was binding to wrong address in address list because on Windows there were multiple IP addresses plus both IPv4 and IPv6

I will post some interesting code later)

Thanks!
esp32> iperf -c 192.168.1.199 -p 5555
I (73326) iperf: mode=tcp-client sip=192.168.1.198:5001, dip=192.168.1.199:5555, interval=3, time=30
esp32>
Interval Bandwidth
0- 3 sec 0.57 Mbits/sec
3- 6 sec 0.00 Mbits/sec
6- 9 sec 1.18 Mbits/sec
9- 12 sec 0.52 Mbits/sec
12- 15 sec 0.52 Mbits/sec
15- 18 sec 0.35 Mbits/sec
18- 21 sec 0.35 Mbits/sec
21- 24 sec 0.17 Mbits/sec
24- 27 sec 0.31 Mbits/sec
27- 30 sec 0.17 Mbits/sec
0- 30 sec 0.42 Mbits/sec
I (103988) iperf: iperf exit

Who is online

Users browsing this forum: No registered users and 82 guests