Shop OBEX P1 Docs P2 Docs Learn Events
problem with HydraEtherX samples — Parallax Forums

problem with HydraEtherX samples

gonzobrainsgonzobrains Posts: 27
edited 2009-09-22 05:06 in Propeller 1
Okay, so I broke down and bought a HydraEtherx...

I am trying the TCP Server test for the first time. If I start the server on the HYDRA before starting the client on the PC everything is all good. But if I start the client first and then start the server, the client waits awhile, then returns and a "received -1 bytes" data is ZZ ZZ ZZ ... error.

If I start the client again it works great.

Is this just an error in the client code because it's not robust? Does it need to retry more? I'm going to look into it more and see if I can improve it. I just wanted to know if anyone else saw this.

Jeff

Comments

  • saverysavery Posts: 12
    edited 2009-09-16 22:58
    I never tested having the client started before the server. In client/server models you sort of always assume that the server is started first and then listens for the client.

    By default, when establishing a connection, the W5100 retries 8 times every 200ms. So, if there is no server up and running in 1.6 seconds then it will timeout (you can verify the timeout by looking at a bit in the interrupt register). I imagine this is what is going on for you. The client is simply timing out before you get the server started.

    Your going to need to make a few extra API calls if you want to do this. There are two registers you care about, Retry Time and Retry Count. Check out the W5100 data sheet. It is located in the CD that came with the EtherX card. That will tell you what address locations Retry Time, Retry Count, and the interrupt registers are located. Once you know that you can use the "write" API call from the EtherX driver so set the values you want.

    Hope this helps.
  • saverysavery Posts: 12
    edited 2009-09-17 13:47
    Woops! Just noticed that your client is the PC. My first post if valid if you make the Hydra a client and have server on the PC.

    The problem is still the same although I don't know of the top of my head how you would tell the client on the OS to retry more.

    Bottom line, always start the server first.
  • gonzobrainsgonzobrains Posts: 27
    edited 2009-09-21 18:50
    I understand what you are saying but my idea was just to make my code more robust on both sides. For example, what do you do if the connection is lost even though the server has already started up? Technically, the server did start up first but the link ws down. How do you make things more robust in that case?

    Thanks,
    Jeff
  • saverysavery Posts: 12
    edited 2009-09-22 05:06
    The same thing will happen within the W5100 for a lost connection. The W5100 will send a packet and since the connection is lost it will never receive an ACK. It will wait for a time specified in the Retry Time Register and then re-send the packet. Once it has tried to re-send the number of times specified in the Retry Count Register then the Timeout interrupt bit is set.

    To make the driver more robust you could for example monitor the timeout interrupt bit and if you detect a timeout then close the socket and re-open it.
Sign In or Register to comment.