Recent

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

GetMem

  • Hero Member
  • *****
  • Posts: 4017
Synapse TCP/IP client and server
« on: February 25, 2020, 08:41:12 pm »
Since there are very few examples out there, I would like to share a TCP/IP component based on synapse + a small demo application. I hope you will find it useful.
In order to compile the demo, you need two components:
 - Synapse trunk(http://www.ararat.cz/synapse/doku.php/download or OPM)
 - VirtualTreeView available both in 2.0.6 and Trunk. Since the VTV versions are slightly different, I attach two zip files, one for 2.0.6 and one for trunk.

The component supports:
- connection through proxy server(html, proxy4, proxy5)
- encrypted communication
- compressed streaming
- broadcasting
- resource strings which can be easily convert to other languages

The demo was mainly tested with Lazarus Trunk/FPC 3.0.4.
« Last Edit: March 14, 2021, 08:39:48 am by GetMem »

MoCityMM

  • Jr. Member
  • **
  • Posts: 72
Re: Synapse TCP/IP client and server
« Reply #1 on: March 09, 2020, 01:21:32 pm »
Nice! I like it. Thank you for sharing it, adding to my 'howto' repository.

-Mo

nouzi

  • Full Member
  • ***
  • Posts: 188
Re: Synapse TCP/IP client and server
« Reply #2 on: March 09, 2020, 02:27:23 pm »
very nice
my english is  bad
Lazarus 2.0.6 free pascal 3.0.4
Lazarus trunk  free pascal trunk 
System : linux mint 19.3 64bit  windows 7 64bit

chentung

  • New member
  • *
  • Posts: 9
Re: Synapse TCP/IP client and server
« Reply #3 on: January 29, 2021, 05:04:08 am »
wonderful examples !
Thank You !

GetMem

  • Hero Member
  • *****
  • Posts: 4017
Re: Synapse TCP/IP client and server
« Reply #4 on: January 29, 2021, 07:30:47 am »
wonderful examples !
Thank You !
You're welcome! I attach a slightly improved versions.

chentung

  • New member
  • *
  • Posts: 9
Re: Synapse TCP/IP client and server
« Reply #5 on: January 30, 2021, 02:58:31 pm »
Thank You !
I love it !

Guser979

  • New Member
  • *
  • Posts: 23
Re: Synapse TCP/IP client and server
« Reply #6 on: March 14, 2021, 02:53:47 am »
Thank you very much. I was not able to port forward on my router. So I used Zerotier and all the machines are able to access mine with their server.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 512
  • Professional amateur ;-P
Re: Synapse TCP/IP client and server
« Reply #7 on: March 31, 2021, 10:02:45 pm »
Hey GetMem,

This looks very nice and quite interesting.
Definitely needs a good look.
Superb job!!

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

kupferstecher

  • Sr. Member
  • ****
  • Posts: 432
Re: Synapse TCP/IP client and server
« Reply #8 on: May 15, 2021, 11:32:55 pm »
Hello GetMem,

thanks for sharing! I'm studying and trying to understand your code right now, especially the data handling between the threads. Two questions:

1. Multithreading
As I understand you add tasks to the task list e.g. within the main thread, the task list is then polled by the TClientThread of the server application. I don't see any protection there when TList.Add is called in order to add a task (E.g. from TfMain.miBroadcastMessageClick via FTCPServer.SendMessage). The task list is accessed in the Execute method of the client thread and first the count property is checked and then in case it is not zero the list is copied to a local TList. That copy sequence is protected in a critical section, but as the list is thread specific, that critical section seems to protect nothing. Or is it just to guarantee a cache flush?
Additionally I wouldn't expect the access to TList.count to be thread safe, but I'm not sure. Can you say something to that data handling concept?


2. Synapse RecvPacket
You use RecvPacket several times, e.g. in TClientThread.RecvMessage (line 685 of uTCPSockets). I'm not sure about the synapse library, but as far as I understand the TCP-protokoll the incoming data is just a byte stream and not bundled in packets. So when you call RecvPacket how can you be sure that what you receive is the complete data and not only half of a message or several messages combined?

Regards~

 

TinyPortal © 2005-2018