I have an application written in VB.net that runs on a clients pc.
I also have a website written in mostly javascript, http and php.
The thing I want to do is to connect the website to the application, so that when i.e. a certain button is pressed, it connects to the client application and raises an event.
I have tried approaches like TCP socket communication by having a TCP Socket Server running in the background of the client application. I can connect to the server by having a client connection from another vb.net application, but whenever I try to connect through PHP it fails. (I have only tried PHP since server-side scripting seems to make more sense in this case)
Another approach I have tried is to have an HTTP server running in the background of my desktop application and then have a PHP script connect to it, that fails as well.
One thing that I've been thinking about as a last resort is to simply have a textfile on the webserver and a PHP script writing to it after given parameters and then have the client application to read the file every few seconds. But this wouldn't be very efficient with larger amounts of data, would it?
What is the proper way of doing this?
If you have any questions about the code I've been using, feel free to ask.
If you don't get my blurry explanation, try this image: http://i.imgur.com/8njxVFj.png
Thanks in advance.
To have your data more organized i would suggest you to store your data on a database server for example mysql (which is free).
Related
In PHP, is there any way to create, connect and maintain an open (socket)connection so that the connection object can be accessed on several pages?
Imagine a small windows based client program that connects to its server software when you start it. You can send a couple of commands to the server using buttons(lets say start and stop calculation), and receive confirmations on my input.
In this example, when "started", the server will do some counting/calculations and send some values every second to the client which shows this every second until the server is done with its job or you send the "stop" command. The client will also stay connected until you close the program or click some disconnect-button.
How could this client work as a web client running in PHP on the same box as the server software?
I managed to send commands and receive feedback using socket or pfsockopen, but I'm having trouble maintaining the connection since I don't want to reload the page.
I don't want to reload the page every second, so I figured I can use Ajax to execute PHP scripts to read/write to the server without reloading the page, but the script files I execute on the web server can't find my connection resource. I tried saving the resource in session with no luck.
Alternatively, is there any better way of achieving this?
Also: the server software is an old piece of VB6 software, and the web server is on the same box as the VB6 software. The PHP site will work as an interface.
I am writing a chat application for mobile & web using PHP and nodejs-socket.io.
I am using Android to post messenger to PHP - PHP to create a new socket (net library on nodejs) and that response messenger to friend via nodejs.
A (via HTTP Request)-> PHP (via socket)-> NODEJS (via socket.io)-> B
(web - websocket / android)
I was trying A->NODEJS->B use all by socket.io, but the message is slow when the number of users increases.
I found the time for sending messenger from nodejs to B device (chatter) very fast, but socket PHP sending messenger to NODEJS is slow.
I see the socket in PHP/nodejs is opening and closing many times in a short period of time.
Please help me make my application run faster, or suggest a solution?
I expected to try using java, but can anyone tell me anything about websocket performance, i.e. socket.io vs. java socket speeds?
Thank you.
Websocket performance really good, really fast. I tested on Chrome (PC) but not on mobile phone yet.
And Java socket is simple and easy to use. Why don't you use java socket to connect directly from Android -> NODEJS without making any HTTP request and PHP bridge?
The reason why PHP socket repeatedly open and close: There are many reason make your code open and close repeatedly, may be there are no loop in your PHP code to keep the connection. Can you show your detailed code of the problem please?
Im trying to understand how a socket works in PHP.
Lets say I have a file called socket.php, and this creates a socket bound to my localhost on port 99.
Then I run the socket in a while loop so it's constantly connected.
is there a function in PHP to make calls to that socket while its listening?
Another question is: If I have another service such as Java running on a socket -- is it a bad idea to use PHP to connect to the socket to make a call. I ask because I could potentially be recreating new socket connections many, many times.
So is having to reconnect to a socket hundreds of times in PHP bad? Or should I re-use the same socket connection somehow? (I am thinking in terms of AJAX calls to PHP which connects to a Java Socket).
Edit: You can see the example code: https://github.com/JREAM/sandbox/tree/master/php
Im trying to communicate with in socket.php and socket_send.php -- I am leaving socket.php running and opening another console and running socket_send.php and trying to get a result into the console.
Answer to your first Question: I suggest going over here everything you need about sockets is there. Basically the function you want to use is socket_read or socket_recvfrom if using UDP.
Answer to your second Question: Sockets are just a way to send messages to services. It doesn't matter if a client is in php and the server is in Java. Think of it this way. Does it matter that you are viewing a web-page on a linux Web Server with a windows Box?
I have access to a remote Oracle database when using Toad or SQL Developer.
The connection is specified by a TNS record and user+password of course.
Now I wish to have a local webpage that shows (regularly refreshed) data from the database. At first I was thinking of using php but I guess that can only be used on the server itself and I am unable to create files on the server. Of course a server page would be more suitable when there's multiple users but here there's only one.
In fact I just want to do the same as is done by running queries from the tools mentioned, but now called from a custom webpage. I feel this should be possible because the tool has to establish the connection from client to server db also; but I don't know how to set up my local client webpage(s).
Is this possible by applying php or javascript if that's more suitable?
Well you have to understand that the functionality of connecting to oracle database is packaged as part of frameworks, there are no such frameworks in javascript which can help you.
you are right with php, however it needs a webserver to run and they are free :)
the reason why php can connect to oracle database is, it has the framework to do those operations.
for now the answer is no.
or you can see if you can write an Activex which can connect to Oracle database and refresh, microsoft provides framework / api to connect to databases
The best way to do that kind of thing is AJAX: a javascript code calls a PHP page on the web server, this page connects to the DB and returns data to the javascript that updates the page.
I am working on my senior project at university and I have a question. My advisor and other workers don't know much more on the matter so I thought I would toss it out to SO and see if you could help.
We want to make a website that will be hosted on a server that we are configuring. That website will have buttons on it, and when visitors of that website click a certain button we want to register an event on the server. We plan on doing this with PHP.
Once that event is registered (this is where we get lost), we want to communicate with a serial device on a remote computer. We are confident we can set up the PHP event/listener for the button press, but once we have that registered, how do we signal to the remote computer(connected via T1 line/routers) to communicate with the serial device? What is this sequence of events referred to as? The hardest thing for us (when researching it) is that we are not certain what to search for!
We have a feeling that a python script could be running on the server, get signals from the PHP listener, and then communicate with the remote PC. The remote PC could also be running a python script that then will communicate with our serial device. Again, most of this makes sense, but we are not clear on how we communicate between Python and PHP on the web server (or if this is possible).
If any one could give me some advice on what to search for, or similar projects I would really appreciate it. Thanks,
Both php and python can communicate via sockets, so I guess that is a good bet.
In PHP, when you receive the signal from the click button, open a socket to your python app with socket_create.
In python, you would need to implement a server socket (SocketServer) that listens for a connection.
Try reading up on sockets communication in general and socket programming in php and python specifically.
You can set up a web server also on the remote computer, perhaps using the same software as on the public server, so you do not need to learn another technology. The public server can make HTTP requests and the remote server responds by communicating with the serial device.