socket基础使用与函数说明

socket基础使用与函数说明

set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 
$connection = socket_connect($socket,'localhost', 1337); 
while($buffer = socket_read($socket, 1024, PHP_NORMAL_READ)){ 
if($buffer == 'NO DATA'){ 
echo('

NO DATA

'); 
break;
}else{
echo('

Buffer Data:'. $buffer .'

'); 


echo('

Writing to Socket

');
if(!socket_write($socket, 'SOME DATArn')){
echo('

Write failed

'); 

while($buffer = socket_read($socket, 1024, PHP_NORMAL_READ)){
echo('

Data sent was: SOME DATA
Response was:'. $buffer .'

'); 

echo('

Done Reading from Socket

'); 
/*
socket_accept()    接受一个Socket连接
 

阅读全文>>

你可能感兴趣的:(socket基础使用与函数说明)