Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socketting using VFP 1

Status
Not open for further replies.

dkean4

Programmer
Feb 15, 2015
282
0
0
US
In 1999 I have been dabbling with Sockets and I had many problems keeping the connection working. Frequently the sockets would lock up and the app would have to be restarted. Has Socketting improved or stabilized with VFP 9?

I need to communicate between 2 PCs, the other PC being on the other side of the globe. The messages could be as little as a few words up to several paragraphs. The communication is not always going to involve Users on both ends, therefore I need VFP to be able to generate requests and replies from within an app, as well as forward and receive user messages. (Same app on both PCs) It would also be nice to be able to send images, short videos and audio. If not, possibly files could be passed back and forth via Shell Scripts by the VFP apps. No connection should be available for users to access the other PC, (for security reasons.)

If someone has a better idea than sockets, feel free to let me know.

Regards,



Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
AFAIR sockets are built that way, that one main socket waits for requests, spawns a new socket to process a request and so each other socket only processes one request.

Take a look at the example at
frmSock does the main handling of requests and creates a frmSock2 instance via [tt]ThisForm.Addobject( SYS(2015), 'frmSock2', m.tnRequestID )[/tt]
When such a frmSock2 runs, it finally gets to State = 7, and then is removed via Thisform.RemoveObject(lControl.name )

If you only use one winsock you are bound to fail, yes.

Also see
Especially the step Accepting a Connection mentions it, too:
Create a temporary SOCKET object called ClientSocket for accepting connections from clients.

That means your listener socket forwards the connection request to a new socket object, which is finally accepting and processing the connection.

I assume that's what you failed to see or didn't implement, as it's the major non intuitive thing about sockets and breaks the principle of least surprise (POLS). Well, socket handling is very low level, where do you need it anyway? Do you want to implement your own protocol? Once you want to use http, ftp or anything like that, you better don't program on that low level but use libcurl or similar things, like the xmlhttprequest object, it'll handle all the low level stuff you then don't need to care about.

Bye, Olaf.
 
Olaf,

Yes, I believe that you have put your finger on the issue.

I am familiar with xmlhttprequest and have used it in JavaScript to access the backend, in my case, Python. Python, in turn, could access MySQL. But that is straight WEB server design.

I want to use a VFP application (Forms and all) as the proxy for sending user and PC sensor data messages to another PC as well as receive them from the other user PC.

For file transfer, however, is there some quick VFP server like ActiveVFP. I read about it last night, but I have no experience with it. Is it a viable solution? Can it operate as a real WEB server? Can it be built/compiled to operate on its own? Is there some short code example that you could recommend for a primitive solution? I downloaded something, but it is dreadfully abstruse.

Regards,


Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
ActiveVFP runs on IIS, so no, this is not your solution. There is a sample foxpro server, foxpro acting as isapi dll, again, this needs a web server.

But what is so unusual to have a webserver running? If IIS or Apache are to heave weight, there is nginx.

Don't reinvent the wheel. You have to look into how to interface/configure so your own EXE or DLL can act as endpoint, but why reinvent a web server, if there are so many available already?

Bye, Olaf.

Edit: Also look at if you want to use a webserver donn in VFP itself or just take the part of it you need for your own communications without using the HTTP protocol. And finally yes, sockets are then your low level component
 
how immediate does a reply have to be?

Would a message queue be appropriate?

in its most primitive form a single table on a SQL server somewhere that one PC puts requests into (SQL insert) and another picks them up (SQL Select) and adds a reply (SQL update). Main disadvantage is lag time while each end 'polls' at intervals for new messages and increased network traffic when each end would otherwise be idle. Main advantage is that PC 1 can post a request even if PC2 is down (or busy) and PC1 gets a reply when PC2 comes back online. Probably easier to scale as well.

if that is viable this might also be interesting
(ActiveX version)

hth

nigel
 
nigelgomm

Actually, SQL is a nice idea. If it was trivial data, I would dabble with it. My objective, however, is to not involve external stop-overs because the information exchanged is critical in several ways. Half of the time it will be Machine commands and sensor readings and the other half will be data between users which must be secured. It does not have to be Real Time, but it has to be direct between two endpoints.

Thanks for the idea...

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
Olaf,

That is exactly why I wanted to use the sockets. And I can also try WEB Sockets. But I do not want to have an external server, now that I have done some thinking. I was just reading about Web RTC. To me Sockets appear to be the most adequate

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 

if realtime is not a requirement wouldn't a sql server option be the most secure?

Error recovery, load and availability issues all but go away (as compared with a direct socket interface).

n
 
Nigelgomm,

I like Rick Strahl and many of the implements he offers. My problem is that I have lost the license IDs for all of my former purchases and I have had to purchase some a second time. Also, I do not make use of most of the features included in his products. Rick is a great guy, though. Thanks.

Doing it with MySQL on the back-end is very easy for me. I am quite familiar with Server-side MySQL and it would be elementary for me to implement. But I need a more direct route. Maybe I should revise my comment about real time as well. Right now I am going to keep looking for some peer to peer method. The MySQL idea will come in handy in some other way, like a light weight chatting. For that thank you very much, Nigelgomm. It is quite astute.

Something I am looking at, right now, is WebRTC. Secondly, WebSockets might be less prickly than the VFP Sockets, though VFP Sockets is my number one choice. I would love to find a stable working code sample for it. I found one which I will be testing for the next few days, but I have some doubts about it.

Many thanks for your help.

Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
> I would love to find a stable working code sample for it.
I pointed to the wiki example. What is unstable with it? Just expand the frmSock2 class to process your requests, don't change the major frmSock, it's the handler of all ConnectionRequest()s, while all Accept()s are from frmSock2 instances.

wiki comment on frmSock ConnectionRequest method said:
* Because it might be, that we want to have more than one single
* connection active, we need a method to do a pseudo multi
* threading. I have "stolen" this idea from EETAServer ---
* Thx btw --- and have later on noticed that this already is
* [highlight #FCE94F]recommended[/highlight] in the online help.
This is not just a recommendated way to do it, but a must have. And once you do that your sockets are stable.

So Winsock is stable enough, but a http server takes away many more tasks you have to program yourself, for example Winsock itself does not implement any protocol. Don't waste your time on doing, what others already have done. If a webserver itself does not do something, there are handlers/modules for it. Load Balancing, DDOS attack prevention, IP filters, what you like.

What makes you think you get a better experience with low level Winsock, do you think you can only let a webserver forward requests to PHP,Perl,Python? ActiveVFP is adding the .avfp extension to let IIS start up PRGs. Do you think a webserver finally has to serve back HTML? No, http responses have a http header and body, and the http body does not need to be HTML, even browsers request any other file type, eg image files, just to name one thing also coming back via http.

Bye, Olaf.
 
Nice project I didn't knew yet. Thanks Marco!

By the way, I see the announcement of the shutdown of codeplex, what will happen with vfpx, will all this migrate to Github?

I downloaded Fox Pages server and the server itself works, I can't login with the Demo user teste@teste.com.br and Password 123456, but the server runs, I get to the login.

Nevertheless I'd miss that advantage about 3rd party modules with such a fox specific server. I'd rather want to see a Binary nginx.exe for Windows including a built in module/handler for adding further DLL modules and one of them allowing VFP execution. It's a lot of work, though, if the extension should easily enable the use of the same 3rd party modules on Windows, too.

I would still recommend using apache or nginx to use the available modules/handlers for any other aspects aside of the core request handling.
Eg take a look at 3rd party handlers available for nginx:
One big downside: All these modules require a compilation of nginx, so all this rather only is available on the Linux platform. There is a Windows binary of nginx.exe, but you can't configure and load modules dynamically at runtime. Apache allows that, as it supports DLL modules. Very specifc DLLs, not just COM Server DLLs you coudl do in VFP, but anyway, with a little C++ you'd be able to bridge apache to VFP, I'm qute sure.

Since about a year there are dynamic modules in Nginx, too: But I heaven't heard of any Windows support for this.

Anyway, you have lots of modules, which are very useful and can be chained to whatever you add as core request response. It's just a matter of time to get his going in Windows, too.

Bye, Olaf.
 
Hi Olaf, indeed all vfpx projects are going to github! Though I did developed a similar ( but using a thread pool just like apache ) multithreaded web server called "no-fox" I pointed you to FoxPages server because it is public and you can tweak it. I recently thought about using nodeJs through a COM extension just to play with the latest tech since my http processor is a vfp mtdll ( ) but then I realized that it would break the main goal , wich is to provide the platform to develop self-hosted vfp microservices with ease and simple deployment. Microservices provide the path to 'break' monolithic applications, and allows you to add/migrate functionallity to a free, rich echosystem, where you can choose the right tool for the job as long as it provides a http exposed api.

Marco Plaza
@vfp2nofox
 
This microservices concept doesn't contradict the recommendation of a webserver already much more matured and already having a bunch of 3rd party add ons to use.

The downside of course is not yet any module allowing direct usage of a VFP prg, but my thought is it shouldn't be too complicated to get there without starting from Winsock, no matter if MS Winsock or SocketWrench. I remember how that was discussed about 10 years ago.

FoxPages being public gives it the potential to attract other contributions, but will it really ever get where nginx already is? I am currently tempted to take a look at nginx sources or at least how to create a new module/handler. Already found a good basis for own module development at the only thing blocking me is I rather want to contribute to strategies of migration from FoxPro to other development platforms than prolonging VFPs life.

Technically I am with you and think of using and digging into ODATA services, my favorite Restful approach of providing data in a non sql way, starting from very atomic access of single entities up to services you might well put under that roof of microservices. HTTP surely is a very nice backbone of very many things.

I never supported monolithic apps in my whole development life, as I started for the customer of a software company, that customer was already using a landscape of multiple applications using multiple databases with strong interfacing of each others data. Admitted, they rather had several monolithic systems, but not one monolithic unmanagable system. I maintained several of these applications and contributed data warehouseing and introduced a service oriented interface, not the classical SOAP base SOA. As this was a pure VFP landscape my choice of the service bus was not server side http protocol based but via APP files used as class libraries, which could be extended, built and maintained independent from the main applications lifecycle and update their dependencies independently - this was helping to relieve the stress of many developers and turn it into my own stress. These app modules provided an easy way to get an interface instance to AppX data for AppY with methods and naming conventions and result structures of AppX data customized to AppYs way of working, yet still centralising one domain, one topic of data to one database for it, no redundancies, not simply copying over endpoint data of AppX to starting point data of AppY, also not just one way.

Guess what they now migrate to? A monolithic PLM (product lifecycle management) system rather meant for a totally different business. A system initially implemented by a company for their internal use, which they finally did not use themselves, a dead on arrival software.

Okay, enough ranting on my development life. I recognize such things like Fox-Pages and No-Fox are not really starting from scratch but based on a repository of tested in time VFP code and some helper libraries. But I just think about Carlos Alloattis effort of a libcurl VFP implmentation and Craig Boyds VFPConnection at the same time, though that topic is well covered by Rick Strahl. Also Craig Boyds VFPCompression and dFPUGs own zlib based dFPUG-ZIP.FLL - time of good developers invested into same topics, who could have done different things instead. Wasted time, in my eyes. And in the same sense, why not look for something already there to extend than again starting from scratch? I know it's a way of feeling independent and having achieved something on your own, building everything fully on own concepts, but opening the door to an already existing house is enabling to use all that and not just one more http server.

Bye, Olaf.
 

Because the problem is not just the server.. in fact you already have IIS available with every windows machine and plenty documentation on how to run VFP as a back-end using FoxIsapi, WebConnection, ActiveVFP or FoxWeb. The main benefit of self hosting using a vfp server is the ease of deployment, configuration, debugging and natural integration with vfp. Just start your app and your server is ready.













Marco Plaza
@vfp2nofox
 
Well, going back to the inital post:

Dennis Kean said:
I need to communicate between 2 PCs, the other PC being on the other side of the globe.

I would rather only do that on the basis of a full http server than on something implemented in VFP with sockets.

Bye, Olaf.
 
Olaf said:
Just expand the frmSock2 class to process your requests

What do you mean EXPAND frmSock2?

frmSock2 is is referred to in frmSock. What is there to expand?

I tried running it on two separate machines, one as Server and one as Client, on my local network and the client does not come up. It locks up. Same problems I was having with Winsock 20 years ago. And 20 years ago I figured that out, but I cannot remember what the problem was.

Most importantly, I need to compile this client app and send it to my clients. They do not have VFP IDE. So, I broke it apart and created a project and the Server, now is unable to get past this line of code:

vvvvvv_ixqy8o.png


It first asks me to select the right object, which tells me that my DEFINE statement is not visible to the form. The server does not do that in the original code.

I copied it from the source and added it as a SET PROCEDURE TO Socket_Server.prg.

zzzzzzzzzzz_ugfcvu.png


All the DEFINEs should be visible. The textbox "bEditBox" is in the PROC file too and it gets created in the form Init Method.

Code:
LPARAMETERS tnport
THIS.nport = tnport
THIS.ADDOBJECT('EditOut', '[b][COLOR=#00aa00]bEditBox[/color][/b]')
WITH THIS.editout
	.TOP      = 60
	.LEFT     = 10
	.WIDTH    = THIS.WIDTH-20
	.HEIGHT   = THIS.HEIGHT-(.TOP+5)
	.READONLY = .T.
	.VALUE    = ''
	.VISIBLE  = .T.
ENDWITH
THIS.ADDOBJECT('txtStat', 'TextBox')
WITH THIS.txtstat
	.TOP      = 10
	.LEFT     = 10
	.WIDTH    = 20
	.READONLY = .T.
	.CONTROLSOURCE = "ThisForm.nStat"
	.VISIBLE  = .T.
ENDWITH
[COLOR=#FF0000]THIS.ADDOBJECT('oSock', 'frmSock' )[/color]
THIS.osock.LISTEN()
THIS.VISIBLE = .T.


Dennis Kean

Simplicity is the extreme degree of sophistication.
Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top