服务器端:
<?php
set_time_limit(10);
//* 设置不显示任何错误 */
//error_reporting(0);
function varinfo($str) {
echo "<pre>";
var_dump($str);
echo "<pre>";
}
$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 "监听成功";
}
}
}else{
echo "监听失败";
}
//$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);
?>
客户端:
<?php
$errno='001';
$errstr="socket file error";
$fp = fsockopen("192.168.3.57", 1337, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />\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);
?>
关键词标签:php,socket
相关阅读
热门文章 plsql developer怎么连接数据库-plsql deve2021年最好用的10款php开发工具推荐在 PHP 中使用命令行工具php应用程序安全防范技术研究
人气排行 详解ucenter原理及第三方应用程序整合思路、方法PHP中防止SQL注入攻击PHP会话Session的具体使用方法解析PHP运行出现Notice : Use of undefined constant 的解决办法CakePHP程序员必须知道的21条技巧PHP如何清空mySQL数据库PHP采集图片实例(PHP采集)plsql developer怎么连接数据库-plsql developer连接数据库方法
查看所有0条评论>>