Forum > Networking and Web Programming

How to do Warfley simple websocket server sample on a form not in console

<< < (3/3)

PierceNg:

--- Quote from: Warfley on February 14, 2023, 07:27:27 pm ---As my name is in the titel, I feel as if I should also answer to this thread.

--- End quote ---

Hi Warfley, thank you for making your software available and chiming in.

A comment/question: Your console chat server example runs a "while comm.open do stuff" loop. To emulate that, for LCL, my code  does "while comm.open waitFor(INFINITE)". It feels unaesthetic to do a while loop (that waits indefinitely) in an event-driven GUI cum network server app. Is there a better way currently in the library to do the same thing?

Warfley:
When the client is connected, the handler is created and "HandleConnection" is called. The Threaded Handler then starts a thread which does the following:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  try    Recv := CreateReceiverThread(arg.Communicator, Arg.Pooling);    try      Arg.Communicator.SetCustomReceiveMessageThread(Recv);      Arg.Handler.PrepareCommunication(arg.Communicator);      Arg.Handler.DoHandleCommunication(arg.Communicator);    finally      Recv.Stop;    end;    Sleep(20);  finally    Arg.Handler.FinalizeCommunication(arg.Communicator);  end;So what happens here is that a separate receiver thread is started, and then the handling loop is executed. Once the handling loop finished, the Receiver Thread is stopped, and afterwards the communicator is Finalized.

If you don't want to have that loop you need to create your own TWebsocketHandler, which creates it's own receiver thread start/stop mechanism.

I may later today create a simple example for an event driven handler

Mongkey:
Sorry guys, once more question:
How to terminate created wssthread?

1.wssthread.terminate;
   wssthread.free;
2. Killthread(threadId);
->threadid = wssthread.threadid. directly after created.

ws streaming does not stop.

Thank you.

Warfley:
As promised a new example: https://github.com/Warfley/LazWebsockets/tree/master/examples/lcl_example/server

Is a bit lazy on some points, but I think this shows clearly how to build such a thing event driven and how to handle the events that occured on different threads on the mainthread (through TThread.QueueAsyncCall).

But I think this could be done easier with some minor modifications to the library (basically the event calling functions must be overridable so one can simply inherit isntead of creating a whole new wrapper.
There are some other things I want to change in the future, so maybe I am going to update the library soon™

Mongkey:

--- Quote from: Warfley on February 15, 2023, 07:10:35 pm ---As promised a new example: https://github.com/Warfley/LazWebsockets/tree/master/examples/lcl_example/server

Is a bit lazy on some points, but I think this shows clearly how to build such a thing event driven and how to handle the events that occured on different threads on the mainthread (through TThread.QueueAsyncCall).

But I think this could be done easier with some minor modifications to the library (basically the event calling functions must be overridable so one can simply inherit isntead of creating a whole new wrapper.
There are some other things I want to change in the future, so maybe I am going to update the library soon™

--- End quote ---

Thank you bro, your LCL sample is more than enough.  :)

Navigation

[0] Message Index

[*] Previous page

Go to full version