Python TCP client

Hi,

I have a WIZ550S2E module, I’m writing a python application that must send data to the serial port over TCP…

I tried to write a really simple TCP client, I can connect to the WIZnet TCP server, send data, but I never receive a response, I just get a timeout.

Could someone tell me what I am doing wrong ? Thank you !

Here’s a minimal code sample:

import socket
import time

ip, port = '192.168.1.150', 6000

# Open a TCP socket with a 1 second timeout
sock = socket.socket()
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.settimeout(1)

# Connection is OK
sock.connect((ip, port))
print("Connected to %s:%s" % (ip, port))

# Send the connection password
sock.sendall(b"WIZnet")

# whatever I send here, I get no response
#sock.sendall(b"Hello")

# this gives a timeout
print(sock.recv(1024))

Running the code:

$ python tcpclient.py
Connected to 192.168.1.150:6000
Traceback (most recent call last):
  File "test.py", line 19, in <module>
    print(sock.recv(1024))
socket.timeout: timed out

Here’s a screenshot of the configuration tool:

FWIW, here’s a screenshot of the packets captured by wireshark when I run the sample code:

Hi izimobil

Is there any reason you put timeout ?
I think the timeout is too short and no need it.

And WIZ550S2E does not loopback your data.
It bypass tcp data to uart data. (so the name is WIZ550 serial to ethernet module)
If you want to check data from PC, you need connect WIZ550S2E and PC via uart

Any way, could you try it again remove timeout?
And… I still cannot understand why WIZ550S2E send FIN packet…
could you share the wireshark file? no capture.
I want to check the details about first syn packet options.

the below capture is the test between python and 750s2e.
you can check the data from uart terminal.

thank you

Hi Lawrence !

Many thanks for your reply.

If I disable the timeout, the script hangs indefinitely on the “sock.recv(1024)” line, meaning that it receives no response from the unit with the WIZ550S2E card.

I realize I wasn’t very clear on what I’m trying to achieve.
I’m writing a software (running on a PC) that want to send and receive packets over TCP to a serial based software running on a micro-controller with a WIZ550S2E card connected to it’s serial port, so the communication should be bidirectionnal.

Here’s a diagram:

diagram

I attached the wireshark file of the script running with the timeout removed.
test.pcapng.zip (721 Octets)

Thanks !

Hi again,

If it can help, I tried via telnet, and same: I can send data but not receive.

Here is a telnet session that closes because I did not sent the password in 5 seconds (normal):

$ telnet 192.168.1.150 6000
Trying 192.168.1.150...
Connected to 192.168.1.150.
Escape character is '^]'.
Connection closed by foreign host.

And one that stays up because I sent the password (note that there’s no response):

$ telnet 192.168.1.150 6000
Trying 192.168.1.150...
Connected to 192.168.1.150.
Escape character is '^]'.
WIZnet
+++

Attached the wireshark file for the second telnet session.
telnet.pcapng.zip (797 Octets)

Thanks.

Hi,

Thank you for more detiails! :slight_smile:

First, I would like to check what you have done for tcp loopback.

I put the picture for explaining WIZ550S2E normal operation and what customer have to do for loopback.

Basically. WIZ550S2E only bypass tcp data to serial data. And… that’s it.
If re-send the received data from serial, mcu must control WIZ550s2e to send the data with send command.

Could you check how the red part you have done?

thank you

If you are looking for the loopback example, here is the link.

hope it will be helpful :slight_smile: