Jump to content
jbWishmaster

sending text between applications (10)

Recommended Posts

I have a unique problem that I am trying to solve

1.

so I am trying to send information to and from ~2-10 applications at the same time, without knowing the IPs of the respective machines.

something like the "OverbyteIcsTWSChat" demo just for max 2-10 people should see the same message at the same time on the same local network.

 

2.

is there a method to get all IP's from all PCs that are connected to the same router/local network. and if not

 

3. 

I have access to every PC so I can get the IP of everyone PC if needed but I would like to somehow solve it automatically and list all IP's in the background.

 

 

I'm trying to implement some kind of log so that everyone in the group knows what the other is doing.

 

I have no experience with this component (ICS)

 

 

 

Share this post


Link to post

There are several possibilities:

1) You get the IP or hostname of each computer in the LAN. You told us you can do it.

2) You write your program with a TWSocket listening on UDP broadcast (See OverbyteIcsUdpLstn demo project). Beside listening, your program will periodically do a broadcast to say "Hey I'm here" (We call that advertizing of service)(See OverbyteIcsUdpSender demo project). That way, each program will know all others on the LAN (UDP broadcast do not go outside of the LAN). One broadcasted message could also say "Hey, who is there?". The receiving program will answer immediately with a message "Hey I'm here".

3) If you need to know the all the PC running your program only once, you can use a port scanner to check all IP on the LAN that listen to a given port. This could be slow or very slow for large LAN. Port scanner can be found for free, Google is your friend.

 

Does it helps ?

Edited by FPiette

Share this post


Link to post


4).  Write a little program which logs the IP in a database (with a lastseen timestamp)


5).  Write central service to which the clients report every x minutes/hours. 

     (we do that here now, maybe going over to MQTT for reporting this stuff, we use this also for servicing a win32 app (3cx, with own build plugin) to automaticly dial phonenr's from our software,

     through the service we are also able to find out if we need to use the phone next to the station or another phone (eg when using RDP to use the application, this service is the crossing point of knowledge of IP nr's,           stations who      using RDP, and the linenumbers of the phsyical phones, (yes the phonenr's are fixed to the physical phone)

     * The client app reports IP, RDP  and application info

     * The 3cx plugin reports also IP and phoneline nr

     * Client app sends to service callnr "xxxxxxxxxxx", service send to the specific 3cx instance, to dial the number).

 

 

Maybe, using something like MQTT works for you also, plenty components available for Delphi. Only have to setup a MQTT service somewhere in your network (server).

 

Edited by mvanrijnen

Share this post


Link to post

You should build the OverbyteIcsIpStmLogTst.dpr sample, and run it on two or more PCs.  It uses the TIcsIpStrmLog component, which can be configured as a TCP or UDP, client or server, and sends lines of text between instances, with just a few lines of code for client or server. 

 

As François says, your main PC can broadcast UDP packets periodically to the clients running a UDP server, they then return their IP address, which you log.   The client PCs also run a TCP Server, which the main PC then sends messages to, TIcsIpStrmLog can send to a list of IPs. 

 

Or your main PC can be a TCP server, and the client PCs keep a permanent connection open for messages, avoids needing to keep IP addresses.  If the TCP client connection from TIcsIpStrmLog drops, there are settings to make it repeatedly retry connections until the server comes back. 

 

All this can be tested without any coding using the OverbyteIcsIpStmLogTst.dpr sample. 

 

If you decide the clients should be servers and you need their addresses, you can instead use the Address Resolution Protocol (ARP) that runs on all network devices to keep track of IP addresses and MAC addresses on the local LAN, it is how ethernet works.  I have an Internet Protocol Helper Component that gets the ARP table.  In the next few weeks, this will get added to ICS with a new sample to list the ARP and IP routing table, current TCP and UDP connections and network adaptors. 

 

Angus

 

 

Share this post


Link to post

Another option if you have Delphi Enterprise would be DataSnap so you don't have to deal with TCP/UDP level stuff directly. :classic_cool:

 

We have a DataSnap service running on a server that all the clients talk to (they know the servers IP).  We send this service the User ID, IP address and other information via an object (DataSnap does all the marshalling) and the service tracks the initial connection time and last seen time.  We store this object in an object list in memory in the DataSnap service.  When the clients connect to this service the DataSnap TDSTunnelSession gives us the unique client and session id's, we then use the DataSnap DSClientCallbackChannelManager.RegisterCallback method to register a callback method to the client with the server.  Now the server knows the IP address and can make a callback to any/all the connected clients passing a TJSONValue so you can pass anything you want and again DataSnap does all the marshalling.  We have built our own messaging/command structure using this TJSONValue and calling methods in the DataSnap service to send messages.  The server then loops thru the list of clients and sends the message to the client(s) via the registered callback.  We can request the client(s) 'Check-In' to is if they are still there, get a list of other/all connected clients, send messages that pop the Windows tray notification and we can even force a termination of the client(s) if needed thru an admin client.  We have even enabled authentication, compression and encryption of all this communication with just a few DataSnap properties.

 

This does put all the work on the server and the clients cannot work/send messages without the server so this will not work if you want direct client to client communications.

 

We built this years ago and it works well for us, but you could build the same type of thing with MQTT, that was our other option.  DataSnap just gave us a few more options/control we were looking for at the time even if there is some DataSnap overhead and a learning curve.  It was also something we already owned and we would not need to include another piece of open source in our software and knew would continue to work and be updated with future versions of Delphi. (we hope)

 

 

Share this post


Link to post
1 hour ago, Tom Chamberlain said:

Another option if you have Delphi Enterprise would be DataSnap so you don't have to deal with TCP/UDP level stuff directly. :classic_cool:

oes put all the work on the server and the clients cannot work/send messages without the server so this will not work if you want direct client to client communications.

 

We built this years ago and it works well for us, but you could build the same type of thing with MQTT, that was our other option.  DataSnap just gave us a few more options/control we were looking for at the time even if there is some DataSnap overhead and a learning curve.  It was also something we already owned and we would not need to include another piece of open source in our software and knew would continue to work and be updated with future versions of Delphi. (we hope)

 

 

Interesting, gonna take a look at (into) this solution,  maybe we use this route also. 
 

Share this post


Link to post

thanks to all who replied.

 

UDP listening looks promising to get the IP's, I only have one computer wired the rest is on the same WIFI
I thought I Send/Receive each IP once every 30 seconds with a command like the IP + Username (because different people use the same laptop)
or if the App Closes it sends the command too remove the the IP from the list, and on the receiving end it checks if the IP and username exist.


so that small program that I wrote is a DB for location/inventory tracking
one of the tasks it should fulfill is, if user 1 changes something then the same change should be made to 
PC/User 2-10, so that everyone sees the same thing. and as I already said the server is very slow 
so Reloading the DB is out of the question it takes a lot of time ~2 min. for a file ~ 1 MB

 

I also try to work with open source. I'm under a lot of time pressure to finish this App.

so if anyone else has other suggestions or Demos to speed it up the process...


 

Tracker.jpg

Share this post


Link to post

One more note : UDP is - by design - an unreliable protocol. There is nothing in the protocol that check for lost packet or receive on twice. So you must take that into account. On a LAN it rarely loose packets, only when there is a congestion. If you need, you must design your own UDP based protocol that somehow check if data sent is received.

 

If you need to send information reliable, then use TCP which is - by design - a reliable protocol with error detection and correction, re-transmitting if needed. If the protocol can't correct the error, you get an error returned to the application.

 

So my advice is: use UDP from his broadcasting feature to discover the computers and then use TCP to transmit data (peer-to-peer).

 

Share this post


Link to post

Grijjy have a wrapper for the ZeroMQ Majordomo protocol at  https://github.com/grijjy/DelphiZeroMQ.  There's a lot of reading to do if you want to learn all about ZeroMQ, but Grijjy supply a simple Client, Worker and Broker to start from, which work 'out-of-the-box'.  The advantage to using a Broker app is that you do not have to sniff around to discover everyone's IP address; each party registers their name and role with the broker and then the broker ensures that messages can be sent to and from each named entity.  You can also combine this with Grijjy's 'protocol buffers' to send almost any type of data that the sender and recipient apps agree upon.  I have started to explore this myself and have not yet discovered any major snags.

  • Like 1

Share this post


Link to post

Just use mailslot component

Great use between Delphi applications

I used it in a large project to send messages and data between application

Share this post


Link to post

Never used Windows Mailslots, don't see any advantage over using sockets, they are limited to messages no more than 424 bytes, and I'd guess are dependent on various network services running.  Microsoft recommends named pipes or sockets as the modern replacement. 

 

Angus

 

Share this post


Link to post

It did work without any glitch

Communicate between 3 computers with Delphi programs

I admit it was a long time ago

Edited by limelect

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×