This FAQ is a work in progress, but I wanted to get it up here since it shows how to communicate via UDP between two forms. It could just as easily have been two processes or computers communicating, but I wanted an example that you could run from a prg file inside VFP for now. The reason I started this project was because I was looking for a way to communicate between all the instances of an application in a multi-user setting without having to create some sort of message queue and check it with a timer. That seem pretty inefficient to me. Things I thought I could do with the ability to send and receive messages in an application was allow system administrators to send out messages to users that a proposed action was about to take place such as "Backing Up the Data in One Minute!". I thought they could even send a message to the running applications on the remote workstations telling them to shutdown gracefully if a user wasn't present to respond. I also thought that it would be an easy way to keep track of all the users currently logged into the application or how many copies were currently running (a sort of LAN strobe if you will) There are other possibilities for this such as sending data back and forth, notification of a change in application state, etc. So, as you can see, though the program is entitled VFP CHAT CLIENT, it is just a simple example that opens doors to many possibilities.
This code uses the MS Winsock control. I am assuming that you have it registered on your computer - if not then do so before running the example. The ports being bound to are 1234 and 1235 - if either of these conflict with something already running on your computer, change them before running.
Possible future changes for this FAQ include:
Choosing protocol TCP/UDP
Binding to different ports
Chat Server to act as relay
HTML and/or XML support
Compression and Encryption of data sent
Sending Files across
Who's Online/Offline List
Special Thanks to Aircon for his code revisions - see Thread184-541348 (I have incorporated some of them here and will incorporate more of his ideas in the future additions to this FAQ).
*CUT-N-PASTE the code below into a prg and run it from within VFP*