Recent

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

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #45 on: February 07, 2023, 06:28:47 am »
@Phoenix
Quote
know that client and server are designed to run on different executables but with the version already available, is it possible to run them on the same executable? The idea would be that each exe has a chance to become server when the active server is shut down. But the exe that will have the active server does not allow you to connect the clients unfortunately.
I don't see an easy way to achieve this. However you can communicate between the server and local client.

Quote
In any case version 10 for what I need is sufficient and working  :).
Thank you
You're welcome!

datilas

  • New Member
  • *
  • Posts: 14
Re: Synapse TCP/IP client and server
« Reply #46 on: February 07, 2023, 07:26:24 pm »
using application GUI works great,
but i am trying to create a daemon service
with the daemon service the service activates normally.
but when I connect with the client returns the error:
"Invalid username or password.(10013)"
Has anyone tried using it as a daemon service?
Can someone help me?

....

in console application the same problem happens

from what I understand is a problem with TThread, which both with daemon and console works differently compared to LCL.

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #47 on: February 07, 2023, 07:59:45 pm »
@datilas
Quote
from what I understand is a problem with TThread, which both with daemon and console works differently compared to LCL.
Windows:
Since windows vista(circa 2007) a service cannot interact with the desktop, meaning you cannot show forms, messages like you would from a regular application. The so called session 0 isolation was introduced for security reason. If you would like to run the server as service, you have to get rid of the visual components. This is easy because de business and UI logic are well separated. You have to move the UI logic to a standard application and communicate with the service/server via sockets, pipes, named pipes, memory mapped files, etc.

Linux:
Unfortunately I have no idea if a daemon can interact with the desktop under linux. Most likely not.
« Last Edit: February 07, 2023, 09:31:27 pm by GetMem »

datilas

  • New Member
  • *
  • Posts: 14
Re: Synapse TCP/IP client and server
« Reply #48 on: February 08, 2023, 07:57:17 pm »
@datilas
Quote
from what I understand is a problem with TThread, which both with daemon and console works differently compared to LCL.
Windows:
Since windows vista(circa 2007) a service cannot interact with the desktop, meaning you cannot show forms, messages like you would from a regular application. The so called session 0 isolation was introduced for security reason. If you would like to run the server as service, you have to get rid of the visual components. This is easy because de business and UI logic are well separated. You have to move the UI logic to a standard application and communicate with the service/server via sockets, pipes, named pipes, memory mapped files, etc.

Linux:
Unfortunately I have no idea if a daemon can interact with the desktop under linux. Most likely not.

I want to put the server with service in linux
and the client with a gui application

the issue is there will be no interaction with the user on the server, only on the client.

so i would like to run the server as daemon or console.

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #49 on: February 08, 2023, 08:37:03 pm »
@datilas
Quote
I want to put the server with service in linux
and the client with a gui application

the issue is there will be no interaction with the user on the server, only on the client.

so i would like to run the server as daemon or console.
Then remove every visual component from the server and you are good to go.

datilas

  • New Member
  • *
  • Posts: 14
Re: Synapse TCP/IP client and server
« Reply #50 on: February 08, 2023, 10:40:11 pm »

Then remove every visual component from the server and you are good to go.
this I already did and the error of my first post occurs (Reply #40)

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #51 on: February 09, 2023, 08:56:13 am »
@datilas
Quote
this I already did and the error of my first post occurs (Reply #40)
"Invalid username or password.(10013)"

Did you provide a password for the server? Something like this:
Code: Pascal  [Select][+][-]
  1. function TDaemon.Start: Boolean;
  2. var
  3.   BindConnection: TConnection;
  4. begin
  5.   Result := inherited Start;
  6.   Application.Log(etDebug, 'Starting server.');
  7.   FTCPServer := TTCPServer.Create;
  8.   FTCPServer.HideErrorMessages := True;
  9.   FTCPServer.HideInternalMessages := True;
  10.   try
  11.     BindConnection := TConnection.Create;
  12.     BindConnection.FIP := '0.0.0.0';
  13.     BindConnection.FPort := '40516';
  14.     BindConnection.FPass := 'daemonpass'; //<-this line
  15.     FTCPServer.Start(BindConnection);
  16.   finally
  17.     BindConnection.Free;
  18.   end;
  19.   Application.Log(etDebug, 'Daemon started.');
  20. end;    

I attach a version where the server is a daemon(only tested on windows).

datilas

  • New Member
  • *
  • Posts: 14
Re: Synapse TCP/IP client and server
« Reply #52 on: February 09, 2023, 03:15:06 pm »
@datilas
Quote
this I already did and the error of my first post occurs (Reply #40)
"Invalid username or password.(10013)"

Did you provide a password for the server? Something like this:


I attach a version where the server is a daemon(only tested on windows).

this example accepts only one connection.
the second connection returns the same error.
"Invalid username or password. (10013)"


tested on windows 10 and windows 7
« Last Edit: February 09, 2023, 03:16:56 pm by datilas »

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #53 on: February 09, 2023, 04:20:15 pm »
@datilas

Most likely the server freezes for some reason, you have to debug it.

Phoenix

  • Jr. Member
  • **
  • Posts: 87
Re: Synapse TCP/IP client and server
« Reply #54 on: February 15, 2023, 06:08:41 pm »
Hi @GetMem I tried to edit your project but I ran into a problem. In the attached application I have inserted a menu item "File > Test" on the server side to send n messages in broadcast but the client does not receive all the messages sent by the server. I made some changes in utcpsockets.pas but the already available features seem to work even with the changes.. :-\
ps. I used laz.VirtualTrees and disabled internal messages from usettings because the client (launched on lazarus) returned a read error when used during testing. Maybe GUI calls need to be "protected"?

Windows 10 64bit
Laz 2.2.4 64bit FPC 3.2.2

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #55 on: February 15, 2023, 07:21:36 pm »
Hi @GetMem I tried to edit your project but I ran into a problem. In the attached application I have inserted a menu item "File > Test" on the server side to send n messages in broadcast but the client does not receive all the messages sent by the server. I made some changes in utcpsockets.pas but the already available features seem to work even with the changes.. :-\
ps. I used laz.VirtualTrees and disabled internal messages from usettings because the client (launched on lazarus) returned a read error when used during testing. Maybe GUI calls need to be "protected"?

Windows 10 64bit
Laz 2.2.4 64bit FPC 3.2.2
You are on the right track, protecting with CriticalSection is not enough though, you have to wait until the lock is lifted, before you can add or remove a task. The attached solution works, but is far from ideal.

PS: I'm working on a second edition...
« Last Edit: February 15, 2023, 07:25:55 pm by GetMem »

Phoenix

  • Jr. Member
  • **
  • Posts: 87
Re: Synapse TCP/IP client and server
« Reply #56 on: February 15, 2023, 09:04:35 pm »
You are on the right track, protecting with CriticalSection is not enough though, you have to wait until the lock is lifted, before you can add or remove a task. The attached solution works, but is far from ideal.

PS: I'm working on a second edition...

Indeed the test works  :). But trying to send a file, the client freezes (see reply #42).

Thanks and sorry for the extra work

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #57 on: February 15, 2023, 09:58:03 pm »
Quote from: Phoenix
Indeed the test works  :). But trying to send a file, the client freezes (see reply #42).

Thanks and sorry for the extra work
The pinging mechanism was also effected by your modification. Please try again, I don't see any freezing now.
« Last Edit: February 15, 2023, 10:03:15 pm by GetMem »

Phoenix

  • Jr. Member
  • **
  • Posts: 87
Re: Synapse TCP/IP client and server
« Reply #58 on: February 16, 2023, 04:11:59 pm »
The pinging mechanism was also effected by your modification. Please try again, I don't see any freezing now.

Ok thanks, it works almost perfectly  :). It no longer freezes "permanently" so requests are all accepted. But if I send a file large enough to allow me to send a simple message, when I press "send", the client becomes unresponsive until the download to the server has finished.

From what you wrote, it doesn't happen to you. From code the call to SendMessage is directed on thread so shouldn't it leave the button in the "pressed" state and not allow me to move the form?
However, the problem is keeping the tasklist locked for too long. So I edited again:

Code: Pascal  [Select][+][-]
  1.     if (not FNeedToBreak) and (not FTaskList.FBlocked) then//#
  2.     begin
  3.        //mod
  4.        FTaskList.Lock;
  5.        try
  6.          if not FTaskList.IsEmpty then
  7.          begin
  8.            ProcessTask(TTask(FTaskList.FList[0]));
  9.            FTaskList.DeleteFirst;//.FList.Delete(0);
  10.          end;
  11.        finally
  12.          FTaskList.Unlock;
  13.        end;
  14.     end;
  15.  

with this

Code: Pascal  [Select][+][-]
  1.     if (not FNeedToBreak) and (not FTaskList.FBlocked) then
  2.       //#
  3.       if FTaskList.GetNextTask(CurrTask{%H-}) then
  4.       begin
  5.         ProcessTask(CurrTask);
  6.         CurrTask.Free;
  7.       end;
  8.  

It seems to work fine but I don't know if there is anything else to consider..

balazsszekely

  • Guest
Re: Synapse TCP/IP client and server
« Reply #59 on: February 16, 2023, 04:52:45 pm »
@Phonix
Quote
Ok thanks, it works almost perfectly  :). It no longer freezes "permanently" so requests are all accepted. But if I send a file large enough to allow me to send a simple message, when I press "send", the client becomes unresponsive until the download to the server has finished.
Please note that synapse use blocking sockets, with limited support for non-blocking mode. While you send a large file you cannot send a text in parallel, unless you spawn another worker thread both on the client end server side, just for the file transfer. I can make the client  more responsive(see attachment), but the transfer won't be faster.
You can even complicate things by sending a large file from client to server and in the same time another large file from server to client. It won't work in parallel either in the current implementation.

Quote
It seems to work fine but I don't know if there is anything else to consider..
Code: Pascal  [Select][+][-]
  1. if (not FNeedToBreak) and (not FTaskList.FBlocked) then
  2.       //#
  3.       if FTaskList.GetNextTask(CurrTask{%H-}) then
  4.       begin
  5.         ProcessTask(CurrTask);
  6.         CurrTask.Free;
  7.       end;
The task list is not locked, one ore more task can be overwritten or deleted. Even if you manage to copy the next task in a safe way, ProcessTask won't work faster, you need extra threads.
« Last Edit: February 16, 2023, 04:56:47 pm by GetMem »

 

TinyPortal © 2005-2018