Design: communication to another machine from within a dll lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- tparry_venture · 2015-08-23 21:27 I am new to networking so need some help in the right direction please. I have a dll that is called from an application program on a periodic basis varying between 1 and 10ms. I would like to send some data to another machine that would have a gui in FPC or delphi or other language to display the data in some processed way to give insight as to the state of the dll processing. Not sure yet about the size of the data but might 1kb at a time. Is using one of the libraries such as Synapse or LNet good for this feature? Would I be better off using UDP and/or TCPIP (maybe that is not the correct terminology, sorry) get the data across - mostly one way to this other machine. Both the dll machine and the other machine are most likely windows os 8 or greater. ---------------------------------------------------------------------- aidv · 2015-08-24 00:30 My impression is that you simply want to transfer information from machine A to machine B, both located in the same network. Machine A will run the actual software and also send the information of the software to machine B. It can easily be done with LNet. I am actually using LNet to send and receive data from an iPhone. Be prepared that it will take time to implement network communication, as you will need to do a LOT of debugging and make sure that the data reaches the end-point. Also, be prepared that you will have to do a lot of research from time to time. The process-flow might look something like this: Lets call Machine A = M1, and Machine B = M2, and lets assume that we use LNet. M2 will connect to M1 via TCP or UDP, and M1 will trigger the OnAccept notification event, which we then know that a machine is connected. M1 will then send strings containing information to M2 using the SendMessage() method. It's as simple as that,  but you might want to differentiate commands from eachother. This can be done by sending a string containing a command-identifier. Example: you send the string server_command=myCommand,parameter1,parameter2,parameter3 When M2 receives this string, you parse it by cutting away the part that says server_command= which can be done with the code Code: [Select][b]var[/b] parameterSection := Copy(incomingString ,pos('=',incomingString) + 1, length(incomingString)); and then you split the string "parameterSection" into separate strings at the comma character (',') which can be done with a TStringList using the DelimitedText property. Now, you can use the parameters in any way you want. The first parameter can be name of the command, and the rest of the parameters can be used for information to be viewed. If you want to send data, I'd suggest you use a new socket hosting and connected to a different port alltogether. This way you have one port for commands, and one port for data transfer. I wont spoon-feed you any code as I don't really have the time, but also because the code-implementation can become quite large. But, now at least I have shared one technique that I use. The good thing with my approach, in my opinion, is that one command can contain a lot of information, either for the whole interface, or for a specific task. I hope it all makes sense ---------------------------------------------------------------------- marcov · 2015-08-24 08:50 Probably you need to setup Indy in a thread, with an own handle (allocatehwnd) and eventloop or so, since you can't hook into the parent's eventloop. ---------------------------------------------------------------------- tparry_venture · 2015-08-24 12:40 Thanks for the tips. I will look into LNet and Indy. I started examining Synapse and got the echo working as a simple example. Next I will look to extending that example to handle a message block. Not sure I understand about the creating a thread in the dll with own process message loop.  Will this thread still run after returning from a dll function?