leger lidt med sockets .....
jeg har leget lidt med socket og med lidt hjælp fra php.net er jeg kommet fra til det her :client .php#!/usr/local/bin/php
<?
$ip="172.16.0.72";
$port="23";
$proto="tcp";
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket < 0 ) {
echo " Failed Creating Socket - Reason : ". socket_strerror ($socket) ."
\n";
} else {
echo "Socket Created Successfully \n";
}
echo " Connecting to : " . $ip . " ";
$con = socket_connect($socket, $ip, $port);
if($con <0 ) {
echo "Error... Couldent initialize connection to $ip Reason : ". socket_
strerror($con) . "\n";
} else {
echo "Connection initialized to $port on $ip\n";
}
?>
server.php :
#!/usr/local/bin/php
<?
error_reporting (E_ALL);
set_time_limit (0);
ob_implicit_flush ();
$ip="172.16.0.72";
$port="23";
if (($socket = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) {
echo "Socket Creation Failed because : ". socket_strerror ($socket) . "\n";
} else {
echo "Socket Created successfully - \n";
}
if(($con = socket_bind ($socket, $ip, $port)) < 0) {
echo "Socket Bind Failed because : ". socket_strerror ($con) . "\n";
} else {
echo "Socket Bind Successfully .....\n";
}
if(($con = socket_listen ($socket, 5 )) < 0) {
echo "Failed To Listen because : ". socket_strerror ($con) ."\n";
} else {
echo "Socket listen Successfully....\n";
}
do {
if(($msgsock = socket_accept($socket)) < 0) {
echo "Socket acception failed because : ". socket_strerror ($con) ."\n";
break;
}
$msg =" \n Welcome to Wra Server \n";
socket_write($msgsock , $msg , strlen($msg));
do {
if(FALSE === ($buf = socket_read ($msgsock, 12000))) {
echo "Failed Reading Socket because : ". socket_strerror ($con) . "\n";
break 2;
}
if(!$buf == trim ($buf)) {
continue;
}
if($buf == 'quit') {
break;
}
if($buf == 'shutdown') {
socket_close ($msgsock);
break 2;
}
$msgback = "Server: " . $buf . "\n";
socket_write ($msgsock, $msgback, strlen ($msgback));
echo "$buf\n";
} while (true);
socket_close ($msgsock);
} while (true);
socket_close ($socket);
?>
jeg får følgende fejl når jeg kører min client.php med
php client.php
hvor min server del så kører så melder server.php følgende :
Warning : Socket_read() unable to read from socket [104]: connection reset by peer in /www_files(schat/server.php on line 36
Failed Reading Socket because : operation not permitted
nogen der kan sige om min kode er helt hen i vejret eller det kan fixes ? .. jeg giver gerne mange points hvis det er muligt ....