Jump to content

Socket Connection Help


Asheeown

Recommended Posts

Okay let me start off by saying what I am trying to accomplish here.

 

I am building a website to monitor a program that offers a socket connection and a list of commands to operate the program remotely.

 

The program offers many informational commands that tells the status of what's going on.  It also offers a log command which is what brings me to this.

 

In my program I start up my connection to the program and enter in my password...if all is well, continue.

$fp = @fsockopen($url, $port, $errno, $errstr, 5);

if (!$fp) {
die("Unable to connect: $errstr (Error: $errno))";
}

fwrite($fp, $pass . "\r\n");

 

I enter in a status command and extract the information from it:

 

// Write Status Command
fwrite($fp, "/status\r\n");

// Open new array
$lines = array();

//Distinguish status information from other information
while (!feof($fp) && $str = trim(fgets($fp))) {
if ($str == "---") break;
$lines[] = $str;
}

// Open the information array
$info = array();

// Load the information array
foreach ($lines as $v) {

if (preg_match('/^([^:]+):\s*(.+)\s*$/', $v, $reg)) {
	$info[$reg[1]] = $reg[2];
}
}

 

Everything is PERFECT, the status of the program is posted in front of the user...now here is the tricky part

 

The command to log all information, which I would like to use, is "/log all".  Now when that command is initiated all logged information is posted in the socket connection window (I tried this with a windows telnet client and saw all of it).

 

The goal I am trying to accomplish is to get that information asynchronously as to not kill the socket connection.

 

Any ideas?  If anymore explanation is required just let me know.

Link to comment
https://forums.phpfreaks.com/topic/104125-socket-connection-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.