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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instant Messaging

Status
Not open for further replies.

Imaginecorp

IS-IT--Management
Jan 7, 2007
635
US
Stuck here, how would I pass a parameter and run a procedure on a remote computer on a network.
I know the computer name but am missing something as the procedure is running on my computer...
Trying to write an Instant messaging module in VFP, without the use of the internet...
Not looking for msn or yahoo etc messaging service.
Any and all suggestions would be greatly appreciated...
Thanks
 
Something like

oRemote = CreateObjectEx("Wscript.Shell","Computername")
...

Or do you want to call a Fox Procedure? CreateObjectEx with your own COM server. You got to open the Firewall for RPC if you want to use that.

The same goes for WMI.

You can do Winsock communication on port 80, no firewall problems with that.

Or you would use a timer in conjunction with a job table. In fact you can pass anything you want executed via some job table in a script memo. Also define fields for return values. Communication from peer to peer could also be over a central table.

If you want synchronous then Winsock is the better choice. On the server side there could be an MTDLL listening to requests.

MSMQ is another one.

Bye, Olaf.
 
I had originally started with calling a procedure within a database to send a message… that was stupid. Next I thought of creating a COM (a little exe), but on further thought decided against it because of the registration and security issues Especially on Vista machines, Finally decided on Winsock using UDP protocol as opposed to TCP.
I sub-classed the Winsock ActiveX into one of my classes to ovoid the registration/licensing issues.
I created a container subclass from one of my classes and included the sub-classed Winsock in it to create a separate class (oWinsock)
My calling program creates a subclass of oWinsock as a new object and it is declared public.
Created a form for sending and receiving messages, when the send button is clicked on the form, it sends the text to a method in oWinsock, which in turns sends the message to the remote computer.
When a message is received on the remote computers oWinsock dataarrival method, it in turn starts the message form on the remote computer and displays the message…
That’s it, nothing too complicated.
Finished most of it just have to “Pretty” it up

My question: What is the maximum size of the Get Data buffer and is there a way to check for optimum size, also is there anything I should specifically code for to avoid problems down the road?

Thanks
 
With subclassing you adressed this problem, right?

You can also put the Winsock control on a form and then call/instanciate that form, that will also solve the problem.

Regarding DataBuffer size: If you take it from the UPD paket definition there are two bytes for the paket length and therefore tha max paket size is 64k. But Winsock does take care for the pakets and so in principle there's no limitation I found. The DataArrival will occur when the full data sent by SendMessage has arrived.

You might still slice the answer to a request in chunks of smaller size and add a simple header like MessageGUID/noofpakets/paketnumber to ensure you receive a full message. The TCP protocol is better not only in regard to ensure messages are complete, it's also better in regard to the typical flow of request and answer to that request being done in a connection, might be worth the overhead of having two winsocks, one for listening and one for sending requests in a peer-to-peer situation. If the server side is defined, then you still only need one socket listening of course.

Also take a look at the socketwrnch control instead of using the ms winsock control.

Bye, Olaf.
 
Hello Olaf;

"With subclassing you adressed this problem, right?"
Olaf; you should know me better by now {G}

When I decided on winsock, I had thought about using TCP, with 2 instances, instead of UDP, purely because of reliability and more control, and built a “rough” module, but found the connection was taking a little long at start up, about 3-5 seconds which in today’s world is slow.

This is a simple module purely peer-to-peer and will run only within our app. The reason I don’t want to put winsock on a form is I want the message form to popup whenever a message is received as opposed to keeping the form open all the time.

The purpose here is to basically to ask some user to “release” a document, notify the responsible user when an order is received, send a message when there is an update conflict etc… Though I am sure it will be used for chat as well.

Why do you recommend the “socketwrnch” activex? I have a problem with using freeware or propriety software, happened to look at your discussion on dbmonster.com (boy Olaf, you are all over)…

I finally finished this at 2 am this morning, now will put it through intensive testing…and will post back.

Olaf; as always thanks for your input… appreciate it



 
Well, three things:

1. it's recommended I think even somewhere in the help to put winsock on a form. It does not necessarily need to be the form you use to display, it can be a hidden form, you might even only use it's private datasession as a sideeffect.

2. I'm not all over, it's simply many sites mirroring newsgroups (nntp), dbmonster is one of them. I'm mainly here, on NNTP newsgroups, dfpug (german foxpro user group) foxite and since a few months at experts-exchange. For much longer but seldom at UT.

3. socketwrench is reported to work better, less error prone and faster than the ms winsock control.

Bye, Olaf.
 
This is strange;
Every Second message invokes an error in the SendData(), the Smddata() has the correct remotename and the correct remote port. Winsock is Bound (.Bind(1001)) to the local port in its init method()

Error 1429 Oledispatch exception code 0 from winsock: Invalid argument.

The winsock error is "Invalid arguement". All its doing is sending text. The text is no longer that 20 characters, the dataarrival() buffer is set to 256 spaces.
When the "Retry" button is clicked on the error form (generated by the error routine) and another message is sent it works. Fails on the next one, works on the one after that...
Where can I find the help for winsock?
All suggestions would be greatly appreceated...
Thanks
 
Hello Nigel; thanks for the link, but I dont see how it can help me...All of the examples I have seen and read use the easy 101 approach ideal for presenters but nothing to do with the real world, "create 2 forms call one server other client...."
If the message form was constantly open on a users machine like Live Messenger or Yahoo etc, this would be a no brainer, but my approach is the object (winsock) does not reside on a form but is an object which is already instantiated when the application starts and is "hovering" in the background, when it gets a message (dataarrival()) it pops open the "message form" and displays the message.
It works like a charm and does what it is supposed to but if sending multiple messages from the same machine it fails every second time... The funny thing is if the error is ignored and another message typed and sent it works...
I cant seem to find the help (.chm) files for this...
 
Problem Solved...If anyone is interested in incorporating an Instant Messaging / Chat system in their app, let me know and I will post it...
 
Hi,

the link was more about the general point that chat/IM is coming to VFPX rather than the specific winsock issue - sorry for the confusion.

n
 
Will do... as soon as i finish putting in the final touches (fluff)

Interesting...Chatterfox... As to on the web, Live Messenger, Yahoo messenger etc will do, as to within a Fox application, based on what I have read, its still needs the internet and requires "Basic web development skills..." No Thanks...I say build your own its easy...
 
Have put the "How to" in Forms, classes and controls... I think it belongs in that category... Unless Dave thinks otherwise :}
The "How to" should be used to get an idea on how its done... Its pretty simple and easy... The funny part is it took me longer to figure out the error I was getting than it took to write the whole module. The problem was resolved by just resetting the remotehost and remoteport...

One point I have not understood is everything I have read over the last 2 days says one of the limitations of using UDP as opposed to TCP is that Data must be sent in a single "Send" operation, what does this mean? If it means you cannot send one after the other from the same socket... That is not true... Can anybody clarify?
 
Well, I assume "Data must be sent in a single Send operation" is what you experienced with your error. You need to reset for the next message. It's connectionless, while TCP establishes a connection and then client and server may send messages forth and back until client or server close the connection.

Glad you got it working. With TCP you have a little more overhead but a more stable connection especially if it wouldn't be limited to LAN (eg repeating dropped packages etc). The logic is a bit more complicated. With TCP a socket must choose to .Listen() or not, so you have at least a client and a server winsock for each app client, if you want to support both starting messaging and receiving messages from anywhere.

Then the listening TCP socket will also start a new socket instance to .Accept() a .ConnectionRequest() made to the listening socket. Therefore you'd end up with a client (requester) socket, a server (listening) socket and one socket for each connection accepted. Here's an example for that:
Untested though.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top