View previous topic :: View next topic |
Author |
Message |
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Fri Apr 12, 2013 1:46 pm Post subject: TCPWRITE: when to socketdisconnect? |
|
|
Hi,
I'm using WIZ820I= with W5200.
This is what I do after connecting and stuff:
Quote: | 'TCP send
Result_socketstat = Socketstat(rec_socket , Sel_control) 'SocketStatus rec_socket aktualisieren
Select Case Result_socketstat
Case &H17 'connected
Reset Watchdog
Result = Tcpwritestr(rec_socket , Rec_tele , 255)
If Result > 0 Then
Rec_tele = ""
Alive_interval_cnt = 0
Socketdisconnect Rec_socket
Reset Led1
End If
Case Else 'exeption
Socketdisconnect Rec_socket
End Select |
The crutial point is the "socketdisconnect" right after TCPWRITESTR.
Works fine in many cases, but I encoutered a problem:
If I connect to a second WIZ820IO, sometimes I receive the message, sometimes I don't.
I found out following:
The Server listens, client connects, connection is established. Server reads from buffer, Client disconnects, connection is closed.
If the Server has not finished reading the buffer, while Client disconnects, then the Server does not, or not completly, read the buffer!
It works, if I put a WAITMS 500 before the Clients disconnects. But I dont want that!
Is there a way to determin if transmission is complete, from the clients point of view?
Some kind of ACK that I can receive?
For some reasons I can not:
- wait 500ms
- send an ACK from server to client via TCPWRITE |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Fri Apr 12, 2013 5:33 pm Post subject: |
|
|
I'm off office now, and while watching my little daughter lerning to ride a bicycle, I got an idea myself:
I took the servertest.bas sample as a starting-point for my project, 3000 lines ago. Of corse some adaptions here and there, but I kept the structure.
If you look at the sample, you can see that the input-buffer of the LAN-modul is read only WHILE the socket is ESTABLISHED.
That's not a good idea in my case! I should read from the buffer whenever there is data present, independently from the socketstatus.
I shall try that on monday and report! |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Mon Apr 15, 2013 11:02 am Post subject: |
|
|
I checked it meanwhile.
My ideas was absolutly right:
The client can disconnet immediatly after TCPWRITE.
The server can read the input buffer even after connection has been closed.
The sample is a bit unfair, as it reads the buffer only while the connection is established.
I think in most cases it is a good idea to read the buffer when there is data present, connection established or not. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Apr 15, 2013 11:53 am Post subject: |
|
|
yes after tcpwrite you can disconnect, that is no problem since tcpwrite will write all data or reports an error.
for the server : you could read data that is still in the buffer, it would have been better that at the close status, the buffer is checked and read if required. that is a good point.
I do not know if this works for all wiznet chips. The sample was more or less converted from the wiznet 3100A code, i did not thought about this.
i would not advise to read whatever is in the buffer unless you first have checked that there was a valid connection. _________________ Mark |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|