PHP, Sockets and Non Printable Characters

From: Date: Thu, 27 Jul 2000 14:44:20 +0000
Subject: PHP, Sockets and Non Printable Characters
Groups: php.general 
Request: Send a blank email to php-general+get-8563@lists.php.net to get a copy of this message
Hi, I'm just getting in to PHP and have come across a problem with sockets. I am sending a number of messages to a server I wrote that is currently being accessed by cgi scripts, java apps and windows apps without any problems. The messages I am sending to this server contain no printable ascii characters e.g. chr(31). PHP does nto seem to like this. If I replace the no printable characters with printbale ones then the problem disappears. Changing the server is not an option as it is being used by a number of client applications which can't be changed easily. All suggestions welcome. Regards Julian Here is the relevant bit of code. When the values of USEP, DSEP and FTERM are change to non printable characters things stop working. function initialise_message() { //$USEP = chr(31); $USEP = "|"; $msg = ""; $msg = $USEP; return $msg; } function addtomessage($label, $data, $msg) { //$DSEP = chr(29); //$FTERM = chr(28); $DSEP = "="; $FTERM = "#"; $tmp = sprintf("%s%s", $msg, $label); $msg = $tmp; $tmp = sprintf("%s%s", $msg, $DSEP); $msg = $tmp; $tmp = sprintf("%s%s", $msg, $data); $msg = $tmp; $tmp = sprintf("%s%s", $msg, $FTERM); $msg = $tmp; return $msg; } function terminate_message($msg) { $USEP = chr(31); $tmp = sprintf("%s%s", $msg, $USEP); $msg = $tmp; return $msg; } $fp = fsockopen("server", 5006, &$errno, &$errstr, 30); { echo "$errstr ($errno)<br>\n"; } else { set_socket_blocking($fp, true); // Get welcome message printf("<FONT COLOR=#FF0000>Welcome Message [%s]<BR></FONT>\n", fgets($fp, 255)); // Send initial hand shake info $s_tmp = "connect=Y pack=N context=persistent server=my_box service=my_service user=XXXX password=XXXX\n"; fwrite($fp, $s_tmp, strlen($s_tmp)); printf("Session ID [%s]\n<BR>", fgets($fp, 13)); // build message $msg = initialise_message(); $msg = addtomessage("*SERVICE", "VERSION", $msg); $msg = addtomessage("ACTION", "GET", $msg); $msg = terminate_message($msg); $message = "session_id=0 message=$msg\n"; echo "Message going to server [$message]<BR>\n"; fwrite($fp, $message, strlen($message)); printf("Response from server [%s]<BR>\n", fgets($fp, 100)); fputs($fp,"connect=N session_id=0"); printf("Disconnect [%s]<BR>\n", fgets($fp, 10)); fclose($fp); }

« previous php.general (#8563) next »