php模擬socket一次連線,多次傳送資料的實作程式碼

高洛峰
發布: 2023-03-01 12:20:01
原創
1154 人瀏覽過

 程式碼如下: 
//post.php 
function Post($host,$port) 

//$host="127.0.0.1"; 
//建立連線 = host,$port); 
if (!$conn) 

die("Con 錯誤"); 

//循環發送5次資料 
// 
for($i = 0;$i{ 
$data="user_name=admin".$i; 
WriteData($conn,$host,$data); 
echo $i。 "
"; 

fclose($conn); 

function WriteData($conn,$host,$data) 

$header = "POST /test,$data) 

$header = "POST /test,$data) 

$header = "POST /test.php HTTP/1.1.1]; $header.= "主機: {$host}rn"; 
$header.= "內容類型:application/x-www-form-urlencodedrn"; 
$header.= "內容長度:".strlen($data) ."rn"; 
//Keep-Alive 是關鍵
$header.= "Connection: Keep-Alivenrn"; 
$header.= "{$data}rnrn"; 
fwrite($conn,$header); 
//取得結果 
//$result = ''; 
//while(!feof($conn)) 
//{ 

// $result .= fgets($conn,128); 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜/ 🎜
相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!