Recent

Author Topic: Recommendation for a simple ip client server setup  (Read 3820 times)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Recommendation for a simple ip client server setup
« on: February 19, 2019, 05:41:20 pm »
Hi

I have been experimenting with IPCSimple server, and this does very well as long as its on same PC.

I would like to know what others would suggest for a local network scenario, where the client app sends commands to the server app ( on different local PC) . Needs to be x-platform; preferrably without any libraries.  All that wuld be sent is Text Message, no requirement for any server side scripting engines.

It would be nice if the server could be found by the client, for when DHCP is used to issue IP. Actual Protocol used is not that important; as long as the protocol is native to all OS's.

Thnx in advance

Josh
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Recommendation for a simple ip client server setup
« Reply #1 on: February 19, 2019, 07:39:27 pm »
For a simple client/server scenario? Use FPHTTPServer:and FPHTTPClient (from the package fcl-web). There is some documentation in the wiki, IIRC.
later: Yep, here it is: fcl-web but it lacks info on the simple client/server objects :(
« Last Edit: February 19, 2019, 07:45:53 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Recommendation for a simple ip client server setup
« Reply #2 on: February 20, 2019, 02:04:22 am »
Hi

I experimented with fcl-web, but got no where very fast.

SO I tried indy.

When I place a IdTCPServer on form, set it parameters etc.

When run windows, it works fine.

Running the same on OSX gives error
Threading has been used before cthreads was inititalised.

I have ctthreads as the first unit in uses clause.

Is this a known bug, with OSX?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Recommendation for a simple ip client server setup
« Reply #3 on: February 20, 2019, 02:59:24 am »
Hi

I experimented with fcl-web, but got no where very fast.

SO I tried indy.

When I place a IdTCPServer on form, set it parameters etc.

When run windows, it works fine.

Running the same on OSX gives error
Threading has been used before cthreads was inititalised.

I have ctthreads as the first unit in uses clause.

Is this a known bug, with OSX?

Not a Mac guy, so...

Did you use cthreads or ctthreads? ctthreads would be a typo and should have had a different error.

But using cthreads is required for any non-Windows environment since Indy uses threads in the server.

If its not the main unit in the project, you can also try using the -dUseCThreads define in the Compiler Options for your project.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Recommendation for a simple ip client server setup
« Reply #4 on: February 20, 2019, 08:33:22 am »
hi

just typo..

the app compiles, but will not run

code below.

Code: Pascal  [Select][+][-]
  1. unit serverunit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  9.   cthreads,
  10.   {$ENDIF}{$ENDIF}
  11.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, IdTCPServer,
  12.   IdContext, IdCustomTCPServer;
  13.  
  14. type
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     Button1: TButton;
  20.     IdTCPServer1: TIdTCPServer;
  21.     Memo1: TMemo;
  22.     procedure Button1Click(Sender: TObject);
  23.     procedure IdTCPServer1Execute(AContext: TIdContext);
  24.   private
  25.  
  26.   public
  27.  
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TForm1 }
  38.  
  39. procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
  40. var srec:string;
  41. begin
  42.   srec:=Acontext.Connection.IOHandler.readln;
  43.   memo1.Lines.Add(srec);
  44. end;
  45.  
  46. procedure TForm1.Button1Click(Sender: TObject);
  47. begin
  48.   IdTCPServer1.Active:=true;
  49. end;
  50.  
  51. end.
  52.                                    
  53.  
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Recommendation for a simple ip client server setup
« Reply #5 on: February 20, 2019, 10:01:03 am »
Can you explain why fcl-web/net didn't work? Because things like synapse and Indy are ok, but not your original intention.
If I know why, I can write a simple example.
Specialize a type, not a var.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Recommendation for a simple ip client server setup
« Reply #6 on: February 20, 2019, 01:23:55 pm »
Hi Thaddy,

When I was trying FCL-WEB/Net, i was getting various errors, even some of the examples would not compile ( using latest trunk ).
I suspect most of the errors I was getting were down to not knowing exactly how the components worked, mainly lack of documentation that I could not find.
When I tried Indy, a lot more examples were available; and most worked straight off which were deigned for Indy 10.

I would however prefer to use FCL_WEB/NET as its part of the FPC/LAazarus Components.

What I trying to do is a similar to what IPCServer does but using TCP to allow communication over a network.
ie Server side listening on a port  Ip number can change.
Client sending Text Messages to server, so needs to find server IP I suppose.

Total start and shutdown of the client app is inmportant, as the remote control is a console app that just sends a string based on the extra parameters it receives.
Word PowerPoint LibreWrite etc, can have macros to run external application which allows a simple and effeccient way to allow changinmg of main applicatioin values. Which SimpleIPC does well, but not suited for a network.
for example 
remote_control p1 7689
would send command to main application to change P1 to 7689

I hope that make sense.

Josh
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Recommendation for a simple ip client server setup
« Reply #7 on: February 21, 2019, 10:53:43 pm »
the app compiles, but will not run

In what way exactly?

code below.

The only thing I see wrong is your OnExecute event handler is not syncing with the main UI thread when accessing the TMemo.  TIdTCPServer is a multi-threaded components, its events are fired in the context of worker threads.  So, you can't access your TMemo directly since IdTCPServer1Execute() is run outside of the UI thread, so you need to sync access to the TMemo, such as with TThread.Synchronize() or TThread.Queue(), or Indy's TIdSync or TIdNotify.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Recommendation for a simple ip client server setup
« Reply #8 on: February 22, 2019, 10:58:51 am »
Hi Remy,

Quote
In what way exactly?

If I try to run the bundle, I do not even see the GUI, it just terminates.
If I run the executable, so that I can see the console, and error generted
This is where the message is shown
Quote
Threading has been used before cthreads was inititalised.
Cthreads is the first in the uses clause, compiler option -dUseCThreads is also set.

The button to activate the IdTCPServer1 is on the form, so the server should not be running.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Recommendation for a simple ip client server setup
« Reply #9 on: February 22, 2019, 01:59:05 pm »
Hi Remy,

Quote
In what way exactly?

If I try to run the bundle, I do not even see the GUI, it just terminates.
If I run the executable, so that I can see the console, and error generted
This is where the message is shown
Quote
Threading has been used before cthreads was inititalised.
Cthreads is the first in the uses clause, compiler option -dUseCThreads is also set.

The button to activate the IdTCPServer1 is on the form, so the server should not be running.

Try to move cthreads unit in to main program uses clause (the .lpr file).

 

TinyPortal © 2005-2018