#23242 [Opn]: socket_read(): linux "stop" with 2 or more users connected...
| From: | david at wups dot net | Date: | Wed, 16 Apr 2003 17:20:55 +0000 |
| Subject: | #23242 [Opn]: socket_read(): linux "stop" with 2 or more users connected... | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-37765@lists.php.net to get a copy of this message | ||
ID: 23242
User updated by: david at wups dot net
-Summary: socket_read() o linux "stop" with 2 or more users
connected...
Reported By: david at wups dot net
Status: Open
Bug Type: Sockets related
Operating System: MDK 8.2 / windows xp
PHP Version: 4.3.1
New Comment:
I'm test this script in windows xp (PHP Version 4.3.0)....... but
this script works in windows xp (ph 4.3.0) with 2 or more users
connected......
however, when i try to use this same script on my linux box (mandrake
8.2 php.4.3.1)... and i can't send 2 or more messages without send a
some message in another connection.
(Sorry for my bad English! its powered by
http://babelfish.altavista.com/ )
:)
<?php
ob_implicit_flush ();
error_reporting (E_ALL);
$address = '192.168.0.249';
$port = 1433;
if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
if( !(socket_set_nonblock( $sock ) ) ) {
echo "socket_set_nonblock()" . socket_strerror(socket_last_error()) .
"\n";
exit;
}
if (($ret = socket_bind ($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
if (($ret = socket_listen ($sock, 5)) < 0) {
echo "socket_listen() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
$vtSock = Array();
global $vtSock;
$volta = 0;
do {
$msgsock = @socket_accept($sock);
if (is_resource($msgsock)) {
$vtSock[] = $msgsock;
/* Send instructions. */
$msg = "\nWelcome! \n\r.\n\r";
socket_write($msgsock, $msg, strlen($msg));
}
for ($x=0;$x<count($vtSock);$x++) {
$oSock = $vtSock[$x];
if ($oSock != false) {
$buf = @socket_read( $oSock, 2048 );
if (strlen($buf) > 0) {
$talkback = "TELNET [$x] send: '$buf'.\n\r";
socket_write ($oSock, $talkback, strlen ($talkback));
echo "Hey server, TELNET [$x] send: $buf<br>\n";
if ($buf == 'quit') {
$vtSock[$x] = false;
socket_close ($oSock);
}
}
$volta++;
}
}
} while (true);
for ($x=0;$x<$cdSock;$x++) {
$oSock = $vtSock[$x];
if ($oSock != false)
socket_close ($oSock);
}
?>
Previous Comments:
------------------------------------------------------------------------
[2003-04-16 12:10:32] david at wups dot net
I'm test this script in windows xp (PHP Version 4.3.0)....... but
this script works in windows xp (ph 4.3.0) with 2 or more users
connected......
however, when i try to use this same script on my linux box (mandrake
8.2 php.4.3.1)... and i can't send 2 or more messages without send a
some message in another connection.
(Sorry for my bad English! its powered by
http://babelfish.altavista.com/ )
:)
<?php
ob_implicit_flush ();
error_reporting (E_ALL);
$address = '192.168.0.249';
$port = 1433;
if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
if( !(socket_set_nonblock( $sock ) ) ) {
echo "socket_set_nonblock()" . socket_strerror(socket_last_error()) .
"\n";
exit;
}
if (($ret = socket_bind ($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
if (($ret = socket_listen ($sock, 5)) < 0) {
echo "socket_listen() failed: reason: " . socket_strerror
(socket_last_error()) . "\n";
exit;
}
$vtSock = Array();
global $vtSock;
$volta = 0;
do {
$msgsock = @socket_accept($sock);
if (is_resource($msgsock)) {
$vtSock[] = $msgsock;
/* Send instructions. */
$msg = "\nWelcome! \n\r.\n\r";
socket_write($msgsock, $msg, strlen($msg));
}
for ($x=0;$x<count($vtSock);$x++) {
$oSock = $vtSock[$x];
if ($oSock != false) {
$buf = @socket_read( $oSock, 2048 );
if (strlen($buf) > 0) {
$talkback = "TELNET [$x] send: '$buf'.\n\r";
socket_write ($oSock, $talkback, strlen ($talkback));
echo "Hey server, TELNET [$x] send: $buf<br>\n";
if ($buf == 'quit') {
$vtSock[$x] = false;
socket_close ($oSock);
}
}
$volta++;
}
}
} while (true);
for ($x=0;$x<$cdSock;$x++) {
$oSock = $vtSock[$x];
if ($oSock != false)
socket_close ($oSock);
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23242&edit=1