View previous topic :: View next topic |
Author |
Message |
spesh
Joined: 28 Mar 2006 Posts: 10
|
TCP Socket question |
Posted: Wed May 21, 2008 4:05 am |
|
|
I'm developing an application for transfering data over sockets. The client application (Windows C#) connects to a socket and then transfers a reading following a request.
It seems to work fine most of the time, but every now and again I see a message re-transmission (using Wireshark Network sniffer) and then I lose connection and can't re-connect. My PIC code is based on Ex14 supplied with the CCS TCP stack.
My question is this : Is it OK to leave the socket connected whilst the readings are made (this could be a long time, e.g. 1 hour) or is it best to connect, read/write and disconnect each time I want a reading (probably every 10 seconds or so) ?
Regards
Alan |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Wed May 21, 2008 6:48 am |
|
|
hi
in timeout also consider the time after which your connection is terminated by other side. Make this your limiting factor of socket time out as you are not going to distributed system so no question of network overloading is here _________________ sohail khan |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Wed May 21, 2008 9:24 am |
|
|
I had a problem with long term TCP connections at one time. They would stall and I'd need to disconnect and reconnect. What I found in the "tcp.c" file was a few lines with a comment "TODO: review this". Below that were two lines: Code: | //TODO: review this
//DSR ADD 063004
//i do this because if i am a server, i don't want to timeout.
if ( (ps->smState == TCP_ESTABLISHED) && (ps->Flags.bServer == TRUE) )
continue; | Commenting out those lines fixed the problem. The comms still stalled, but after a second or two it would recover.
Since then, I've been able to maintain a continuous TCP connection (continuous data) for days.
Edit: Added the extra comments for the code fragment to make locating it in the source much easier. _________________ Andrew
Last edited by andrewg on Fri May 23, 2008 10:18 am; edited 1 time in total |
|
|
spesh
Joined: 28 Mar 2006 Posts: 10
|
|
Posted: Thu May 22, 2008 7:47 am |
|
|
Andrew
I can't find that line of code in my TCP stack source.
Which version of the stack are you using ?
Regards
Alan |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu May 22, 2008 9:29 pm |
|
|
The CCS port of the Microchip v3.75 stack. _________________ Andrew |
|
|
Dimmu
Joined: 01 Jul 2007 Posts: 37
|
|
Posted: Sun May 25, 2008 8:58 am |
|
|
I don't know if this can help but some of the CCS examples are bugged.
Try to print the state of all the defined sockets in your code. Maybe it is just a question of initialisation of variable.
Dimmu |
|
|
|