Recent

Author Topic: http server application question  (Read 790 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2145
    • Lazarus and Free Pascal italian community
http server application question
« on: November 23, 2020, 10:47:36 pm »
Hi, I have a question. I would like to create a "" (which I would later like to convert to CGI) that receives a text message via a POST call (and so far it's very easy) and forwards this message immediately to another client.

Ex:

client 1 sends "hello world" to my web server

the web server sends the message "hello world" to client 2 (which was connected shortly before).

Let it be clear, however, that it is not client 2 that asks the web server if there is a message for it, but it is the server itself that sends the message to the client.

You say what can be done?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

lainz

  • Hero Member
  • *****
  • Posts: 3924
  • Leandro Diaz
Re: http server application question
« Reply #1 on: November 23, 2020, 11:42:19 pm »
WebSockets is what you're looking for. But there must be a connection established first between the second client and the server, so he knows is listening for future messages as far as I can understand.

xinyiman

  • Hero Member
  • *****
  • Posts: 2145
    • Lazarus and Free Pascal italian community
Re: http server application question
« Reply #2 on: November 24, 2020, 08:26:20 am »
I probably haven't explained myself.

Assume you have created an http server application with lazarus.

Which has only one module and which has in turn only has the action called "index".

Let's pretend that this program responds to the address "http://192.168.1.10:80/index"

Now connect to that address and you will receive "Hello world"

I want that in addition to you seeing the word hello world this is also sent to another client (for example if you are the ip 192.168.1.11 the message must also be received by the client 192.168.1.12).


If I am not clear tell me that I will provide other more complete examples.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Leledumbo

  • Hero Member
  • *****
  • Posts: 8286
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: http server application question
« Reply #3 on: November 24, 2020, 09:30:35 am »
Use fphttpclient in the handler, make a good use of the passed TRequest instance to make the forwarded request.

xinyiman

  • Hero Member
  • *****
  • Posts: 2145
    • Lazarus and Free Pascal italian community
Re: http server application question
« Reply #4 on: November 24, 2020, 09:33:38 am »
I do not understand what you mean.
« Last Edit: November 24, 2020, 09:38:16 am by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

dogriz

  • Full Member
  • ***
  • Posts: 119
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: http server application question
« Reply #5 on: November 25, 2020, 08:26:59 am »
Or you can make another small server on second client.
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

egsuh

  • Hero Member
  • *****
  • Posts: 571
Re: http server application question
« Reply #6 on: November 25, 2020, 09:07:54 am »
For server to send message to a client which did not send request, I heard that it needs streaming. Unforfunately I do not know how two.

Several years ago Delphi demonstrated it can built messenger funciton --- you can make messenger like Facebook Messenger. Is that what you want? I don't know whether it is possible with Lazarus. 

PierceNg

  • New Member
  • *
  • Posts: 44
Re: http server application question
« Reply #7 on: November 26, 2020, 01:41:56 am »
Let's pretend that this program responds to the address "http://192.168.1.10:80/index"

Now connect to that address and you will receive "Hello world"

I want that in addition to you seeing the word hello world this is also sent to another client (for example if you are the ip 192.168.1.11 the message must also be received by the client 192.168.1.12).

But the other client 192.168.1.12 ought to have been connected to the server for that to happen, no? Otherwise, you are expecting 192.168.1.12 to be running a server program too.

As the previous reply said, websockets is what you are looking for. This is listed on the wiki page: https://github.com/Warfley/LazWebsockets


 

TinyPortal © 2005-2018