views:

829

answers:

3

I'm trying to create a simple AJAX to Telnet client for the web. I may be re-inventing the wheel by doing this, but it is a learning project for myself. At the moment I haven't written anything, I'm just trying to get the idea wrapped around my brain. It doesn't necessarily have to be PHP.

If I have a telnet client that supports multiple connections already running in its own process, how do I get a PHP script that fires off when the client-browser asks to be able to communicate with the client?

For instance, I want the PHP script to be able to tell the already running process which client it is and receive any new data from the telnet process.

+1  A: 

For PHP, your talking about interfacing through the shell right? It would all depend on the telnet client you are trying to hook up with, and what CLI options it supports. Opening a stream to this would probably require having each telnet session outputting its' STDIO to a text file, and then having PHP read that text file and displaying the 'difference'.

With Fsockopen() in PHP, you really don't need to interface with another program though, you can run socket commands directly in PHP and get the results there.

PHP:Fsockopen

Adam
A: 

Even if the connection needs to be persistent?

edit: nevermind, I think I have an idea.

I'll be writing the client part myself, but if it could also act as a server that PHP makes calls to by connecting to it and giving relevant data to so that it can find out which connection the user needs... by George I think I've got it!

edit2: That's what Jim said. Thanks Jim.

A: 

I'd create a telnet client that runs as a daemon process. It would be responsible for creating and maintaining the telnet session and buffers any received data.

Your PHP script could then use a TCP connection, or a Unix socket to communicate with your telnet client daemon process using the PHP sockets API.

Jim.

Jim OHalloran