Difficulty making client TCP connection.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: Difficulty making client TCP connection.
by Eugeny ·
Please edit your post so that code looks properly.
Reusing same local port # and remote port # within several minutes may cause issues when connecting (new session may be treated as old one by router and router may respond with RST); consider using some random local socket #, or use anysocket++ (or whatever it is defined in the library).
Did you set gateway IP address properly? In server mode it does not matter much (as I know), in client mode it is vital because W5500 sends ARP requests to gateway to know other device’s MAC address, and if gateway does not respond properly connect process times out.
RE: RE: Difficulty making client TCP connection.
by sburck ·
Hello Eugeny, thank you for the quick response. I’ll answer in parts:
Tried to find - the only editing control I found doesn’t seem to let me edit the text, only the title.
These are new sessions, not old ones. The code opens the first sockets (server sockets) when it comes up, when the device has something to send on one of the sockets it tries to open a client socket for the first time, and they all fail.
I’ll double check. There is not really a gateway here, as the connections are local (192.168.1.xx via a hub connecting them), If this is an issue, please explain what I might need to do to implement it.
Thanks,
Steve
RE: RE: Difficulty making client TCP connection.
by sburck ·
Found the editor…
RE: Difficulty making client TCP connection.
by Eugeny ·
This is very good news. Connect Windows or Linux PC to this hub, and run Wireshark on it. You will be able to capture all packets on the segment seeing things going on.
When W5500 is given connect command, it tries to resolve IP address of remote deivice to the MAC address sending ARP broadcast. I think there must be some rules who and how devices respond, but I think if there’s anyone on the network knowing MAC address of the IP address (in its cache), then it will respond to the request.
It may happen, while I am not sure, that W5500 may not have ARP cache in it, and may not respond to the ARP request (even for its own IP/MAC combination?), and as there’s no other device knowing MAC address corresponding to the IP address, connecting of W5500 to another W5500 fails…You can confirm or disprove this by looking at the Wireshark capture.I am wrong with it. Just have set W5100 up with gateway address 0.0.0.0, and tried to connect to local PC. W5100 sent broadcast, PC responded and connection was successful.
And vice versa, configured PC with fixed IP address and no gateway IP address, PC sent ARP request, and W5100 responded with its MAC address.
I am afraid we need log from Wireshark to see what exactly is going on.
RE: Difficulty making client TCP connection.
by sburck ·
Again thanks -
I will be able to do this Thursday morning. Until then I have only one box and I’m testing it against itself (setting the IP address to myself, so I send from my clients to one of my own servers - and I’m guessing that it won’t go out on the wire at all).
RE: Difficulty making client TCP connection.
by sburck ·
Hi Eugeny,
Here is what I’m seeing:
I have the client box set at IP 192.168.2.91. This is the one I’m debugging. I have the server box set at IP 192.168.2.90. My PC is at 192.168.2.95, running both Wireshark and, later on, TeraTerm.
At first, I had the gateway set to a non-existant 192.168.2.1. I saw that the call to “connect” generated this in Wireshark:
535 789.643971 AsustekC_15:05:76 Broadcast ARP 42 Who has 192.168.2.1? Tell 192.168.2.95
Now, not sure why it was asking for the reply to the PC, but I know that nothing will answer from the non-existant gateway. So I set the gateway to 0.0.0.0 on the client box. It now generates this:
248 296.352602 Wiznet_ab:cd:ee Broadcast ARP 60 Who has 192.168.2.90? Tell 192.168.2.91
However, to this there is no response.
The PC is able to connect to the server box. When I use teraterm to telnet to port 5001 on the server box this happens:
302 422.122989 192.168.2.95 192.168.2.90 TCP 66 58442 → 5001 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
303 422.123146 192.168.2.90 192.168.2.95 TCP 60 5001 → 58442 [SYN, ACK] Seq=0 Ack=1 Win=2048 Len=0 MSS=1460
And the connection is made, and I can send data to the server box. There does not seem to be anything doing ARP.
The lines of code I have for making the client connection, are, again,
followed by
sn2 is either 4 or 5.
RE: Difficulty making client TCP connection.
by sburck ·
Hi Eugeny,
Changed the parameter in the call to socket from 0xC000 to the port used to send on (sending from port 5001 or 5002 to port 5001 or 5002, port to port), and it now seems to be working. I’ll have to continue testing, but now the client connection is succeeding.
Thanks,
Steve
RE: Difficulty making client TCP connection.
by Eugeny ·
Seems to be the first step is to find out gateway’s MAC address.
And if gateway is not configured, or as a second step, just ask everyone who is the destination MAC.
I suspect PC may have performed ARP earlier if you were connecting before, and MAC-IP address entry is cached in the ARP table of the PC. W5x00 does not have this table, so they explicitly send ARP before any connect request.
Is this source port of the client? If you change from 0xc000 to 5000 and it start working then most probably something may block packets packets with local port # of 0xc000. This is a guess, Wireshark must show what is going on the network when client tries to connect with local port 0xc000 or 5000.