Recent

Author Topic: Synapse TCP/IP client and server  (Read 15716 times)

GetMem

  • Hero Member
  • *****
  • Posts: 3492
Re: Synapse TCP/IP client and server
« Reply #15 on: May 20, 2021, 01:45:58 pm »
@kupferstecher
Quote
there's no doubt that Synapse is working very well. The question was if it can be relied on that a buffer/packet sent via TCP ist received as such packet using Synapse's RecvPacket. In my understanding TCP doesn't guarantee that, but only a stream of bytes in the correct order. Just like a Serial port.
Then perhaps you should switch from RecvPacket to another RecvXY(RecvByte, RecvInteger, etc...). In the end all of them rely on RecvBuffer and the low level Recv function.

kupferstecher

  • Sr. Member
  • ****
  • Posts: 452
Re: Synapse TCP/IP client and server
« Reply #16 on: May 20, 2021, 05:46:01 pm »
Yes, or using RecvPacket and working with an extra buffer.

GetMem

  • Hero Member
  • *****
  • Posts: 3492
Re: Synapse TCP/IP client and server
« Reply #17 on: May 25, 2021, 12:11:48 pm »
@kupferstecher

I fixed the issue with the AddTask method, now everything should be thread safe(see attached projects). If you find a way to improve RecvPacket please let me know, so I can integrate it in the test application. Thank you!

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: Synapse TCP/IP client and server
« Reply #18 on: May 26, 2021, 12:55:04 am »
Hey GetMem,

Do you have this project in a VCS of ANY sort?

I'm not complaining that you give us the source like you're doing now, it's just that you don't give us the source with a different filename, like v1 and v2, well, you get my meaning.

I'm really interested in this code since I'm planing a server of my own and I'm loving that you are reading comments and improving the code, I do, but could we benefit with an historical record?

Many thanks for the code, in whatever form you give to us, though :)

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

irawan

  • Newbie
  • Posts: 2
Re: Synapse TCP/IP client and server
« Reply #19 on: May 26, 2021, 07:58:08 am »
Hello avra,

there's no doubt that Synapse is working very well. The question was if it can be relied on that a buffer/packet sent via TCP ist received as such packet using Synapse's RecvPacket. In my understanding TCP doesn't guarantee that, but only a stream of bytes in the correct order. Just like a Serial port.

Would be interesting to know, how you dealt with this issue, parsing the data stream or relying on packets?

Regards~
as far as i know, UDP that is not guarantee that every packet is sent and received correctly. TCP/IP DOES guarantee that every packet is sent correctly altough packet sequence is not guaranteed. coz of this feature, many router will cut your packet if you exceded your quota. in case your packet is dropped by the router, your server will send your dropped packets again and again till download completed. on other side, UDP can not be limited, it's only option is dropped only.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3406
  • Compiler Developer
Re: Synapse TCP/IP client and server
« Reply #20 on: May 26, 2021, 08:57:46 am »
as far as i know, UDP that is not guarantee that every packet is sent and received correctly.

Just to clarify: UDP does not guarantee delivery, however if it is delivered, it is delivered correctly (meaning without errors).

TCP/IP DOES guarantee that every packet is sent correctly altough packet sequence is not guaranteed.

Packet sequence is guaranteed with TCP (at the recipient, not during transit!), otherwise communication that relies on the order of the data (e.g. file downloads) wouldn't be possible without additional protocols.

kupferstecher

  • Sr. Member
  • ****
  • Posts: 452
Re: Synapse TCP/IP client and server
« Reply #21 on: May 30, 2021, 07:08:36 pm »
If you find a way to improve RecvPacket please let me know, so I can integrate it in the test application.

Hello Getmem,

I checked the Synapse example code for a HTTPServer. There the header is received as string lines, each line is terminated with a line break (CR+LF). In Synapse there is a RecvString Function that calls RecvPacket repeatedly until the line break characters are found. The rest of a packet that is behind the line break is buffered within Synapse and returned the next time RecvBuffer is called. The size of the http-body is part of the headers and the body is then received with RecvBufferEx with predetermined size. This Synapse function calls RecvPacket in a loop until the defined number of bytes is received. The rest of the 'packet' (if the size doesn't exactly fit), again, is buffered back in Synapse. So both http-parts don't rely on any packets but determine the data size to be received on protocol level. And I think such mechanism is required when using TCP.

Packet sequence is guaranteed with TCP (at the recipient, not during transit!), otherwise communication that relies on the order of the data (e.g. file downloads) wouldn't be possible without additional protocols.
As said before, my understanding of TCP is that there are no packets at all exposed to the application but only a byte stream. So your mentioned file download only works if its size is known to the receiver, otherwise it couldn't determine when the transfer is complete. Is this correct?

PascalDragon

  • Hero Member
  • *****
  • Posts: 3406
  • Compiler Developer
Re: Synapse TCP/IP client and server
« Reply #22 on: May 31, 2021, 01:09:33 pm »
Packet sequence is guaranteed with TCP (at the recipient, not during transit!), otherwise communication that relies on the order of the data (e.g. file downloads) wouldn't be possible without additional protocols.
As said before, my understanding of TCP is that there are no packets at all exposed to the application but only a byte stream. So your mentioned file download only works if its size is known to the receiver, otherwise it couldn't determine when the transfer is complete. Is this correct?

On the network level it is composed of packets. The concept of data streams is built upon TCP, but in principle could also be built upon UDP.

And transmitting the length is not the only way to communicate the end of the stream: the sending side can simply terminate the TCP session once all data is send (this is in fact what's happening with HTTP downloads when the server does not transmit the size, though that's rather seldom nowadays).

delphi_coder

  • Newbie
  • Posts: 1
Re: Synapse TCP/IP client and server
« Reply #23 on: September 23, 2021, 01:42:19 am »
As said before, my understanding of TCP is that there are no packets at all exposed to the application but only a byte stream. So your mentioned file download only works if its size is known to the receiver, otherwise it couldn't determine when the transfer is complete. Is this correct?
Here the word packet maybe a bit confusing, packet from your view differs by its meaning in network topic. All data traveling within TCP packets. There is no guarantee that you receive for example 3kb sent packet from the client at once, I think in most cases data checking and using Stream classes or implementing proper buffering is a must.

 

TinyPortal © 2005-2018