時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(1)
服務(wù)器端:
set_time_limit(10);
//* 設(shè)置不顯示任何錯誤 */
//error_reporting(0);
function varinfo($str) {
echo "
";var_dump($str);
echo "
";}
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);
if ($socket) {
$result = socket_bind($socket, '192.168.3.57', 1337);
if ($result) {
$result = socket_listen($socket, 5);
if ($result) {
echo "監(jiān)聽成功";
}
}
}else{
echo "監(jiān)聽失敗";
}
//$path = "/home/upload/";
$path = "e://web//";
while (true)
{
$connection = socket_accept($socket);
if($connection)
{
$msg = "telnet succeed!\r\n";
socket_write($connection, $msg, strlen($msg));
$BufferPond = array();
$buffer = '';
while($flag = socket_recv($connection, $buffer, 1024, 0))
{
if (false !== strpos($buffer,'filename:'))
{
$filename = substr($buffer,9);
$filename = $path.$filename;
$fp = fopen($filename,"wb");
continue;
}
fwrite($fp,$buffer);
}
fclose($fp);
socket_close($connection);
}
}
socket_close($socket);
?>
客戶端:
$errno='001';
$errstr="socket file error";
$fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)
\n";} else {
$str = "filename:socket_file.bmp";
fwrite($fp, $str);??? $out = file_get_contents('../../iphone3G.bmp');
if($out){
fwrite($fp, $out);
fwrite($fp,'over');
echo "上傳成功";
}
}
fclose($fp);
?>
關(guān)鍵詞標(biāo)簽:php,socket
相關(guān)閱讀
熱門文章 plsql developer怎么連接數(shù)據(jù)庫-plsql developer連接數(shù)據(jù)庫方法 2021年最好用的10款php開發(fā)工具推薦 php利用淘寶IP庫獲取用戶ip地理位置 在 PHP 中使用命令行工具
人氣排行 詳解ucenter原理及第三方應(yīng)用程序整合思路、方法 plsql developer怎么連接數(shù)據(jù)庫-plsql developer連接數(shù)據(jù)庫方法 PHP中防止SQL注入攻擊 PHP會話Session的具體使用方法解析 PHP運行出現(xiàn)Notice : Use of undefined constant 的解決辦法 PHP如何清空mySQL數(shù)據(jù)庫 CakePHP程序員必須知道的21條技巧 PHP采集圖片實例(PHP采集)