21,887
社区成员
发帖
与我相关
我的任务
分享
$server = 'xxx.xxx.xxx.xxx';
$port = 'xxxx';
$fp = fsockopen($server, $port);
$flag = true;
while($flag){
$data = fgets($fp,2048);
echo $data.'<br />';
ob_flush();
$content = check_file();
if ($content != ''){
fwrite($fp,$content."\r\n");
}
}
function check_file(){
global $handle;
$file = 'announce/test.txt';
$contents = file($file);
$temp = $contents[$handle];
if($temp){
$handle ++;
$return = $temp;
}else{
$return = '';
}
return $return;
}
if(isset($_POST['content'])){
$content = ($_POST['content']) ? $_POST['content'] : ' ';
$file = 'announce/test.txt';
$handle = fopen($file, 'ab');
fwrite($handle, format_time().'|'.$content."\n");
fclose($handle);
echo '1';
}else{
echo '0';
}
<?php
function format_time(){
list($micro,$second) = explode(' ',microtime());
return date('H:i:s', $second).substr($micro,1,4);
}
function wlog($content){
$file = 'log/'.date('Ymd').'.log';
$handle = fopen($file,'ab');
fwrite($handle, format_time().' -- ' . $content . "\n" );
fclose($handle);
}
?>
<?php
include('function.php');
wlog('begin write');
if(isset($_POST['content'])){
$content = ($_POST['content']) ? $_POST['content'] : ' ';
$file = 'announce/1234.txt';
$handle = fopen($file, 'ab');
fwrite($handle, format_time().'|'.$content."\n");
fclose($handle);
echo '1';
}else{
echo '0';
}
wlog('end writing ' . $content);
?>
<?php
set_time_limit(0);
ob_implicit_flush(true);
include('function.php');
$server = '192.168.1.200';
$port = 7082;
$fp = fsockopen($server, $port);
fgets($fp,2048);
echo fgets($fp,2048),'<br />';
fwrite($fp, "N\r\n");
echo fgets($fp,2048),'<br />';
fwrite($fp,"1234\r\n");
echo fgets($fp,2048),'<br />';
fwrite($fp,"123456\r\n");
echo fgets($fp,2048),'<br />';
fwrite($fp,"y\r\n");
$i = 0;
$flag = true;
$flag2 = true;
$handle = 0;
while($flag){
if ($i % 5 == 0){
wlog('begin get');
$data = fgets($fp,2048);
if (strlen($data) == 0){
break;
}
echo format_time().'--'.strlen($data).'--'.$data.'<br />';
ob_flush();
wlog('begin read');
$content = check_file();
wlog('end reading ' . $temp);
if ($content == 'quit'){
while($falg){
echo fgets($fp,2048),'<br />';
ob_flush();
if (strlen(fgets($fp,2048)) <= 2){
$flag = false;
$flag2 = false;
}
}
}elseif ($content != ''){
wlog('begin write socket');
fwrite($fp,$content."\r\n");
wlog('end write socket');
}
}
$i ++;
wlog('end getting '.$data);
}
function check_file(){
//wlog('begin read');
global $handle;
$file = 'announce/1234.txt';
$contents = file($file);
$temp = $contents[$handle];
if($temp){
$handle ++;
$temp_item = explode('|',$temp);
$return = $temp_item[1];
}else{
$return = '';
}
//wlog('end reading ' . $temp);
return $return;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>发言</title>
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
$(document).ready(function(){
$('#announce').submit(function(){
$.post('save.php',{content: $('#content').val()});
$('#content').val('');
return false;
});
});
</script>
</head>
<body onload="document.getElementById('content').focus()">
<form name="announce" id="announce" method="post" action="post.php">
<input type="text" name="content" id="content" /> <input type="submit" id="submit" value="Go" />
</form>
</body>
</html>
<?php
$file = 'announce/1234.txt';
$handle = fopen($file, 'wb');
fclose($handle);
$file = 'log/'.date('Ymd').'.log';
$handle = fopen($file, 'wb');
fclose($handle);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>PHP Mud</title>
</head>
<frameset rows="*,30" frameborder="no" border="0" framespacing="0">
<frame src="content.php" name="mainFrame" id="mainFrame" title="mainFrame" />
<frame src="post.php" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" title="bottomFrame" />
</frameset>
<noframes><body>
</body>
</noframes></html>