////////////////////////////// File Description //////////////////////////////////////////
// Class Name : socket
// Version : V1.0
// Functional Outline : create socket,and send message to server
// Revision history : 2004/12/15 First version created
// Current : 2004/12/15 Liu Yongsheng
//////////////////////////////////////////////////////////////////////////////////////////
class socket{
var $socket; //socket 句柄
var $sendflag = ">>>";
var $recvflag = "<<<";
var $response;
var $debug = 1;
function socket($hostname,$port){
$address = gethostbyname($hostname);
$this->socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$result = socket_connect($this->socket,$address,$port);
if($this->debug == 1){
if ($result< 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "<br>";
} else{
echo "connect OK.<br>";
}
}
}
function sendmsg($msg){
socket_write($this->socket,$msg,strlen($msg));
$result = socket_read($this->socket,100);
$this->response = $result;
if($this->debug == 1){
printf("<font color=#CCCCCC>%s $msg</fon><br>",$this->sendflag);
printf("<font color=blue>%s $result</font><br>",$this->recvflag);
}
return $result;
}
function close(){
socket_close($this->socket);
}
}