<?php set_time_limit(0); $host = "127.0.0.1"; $port = 2046; $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)or die("Could not create socket\n"); if($socket){ $connection = socket_connect($socket, $host, $port) or die("Could not connet server\n"); socket_write($socket, "Action: Login\r\nActionID: 123\r\nUsername: admin\r\nSecret: password\r\n\r\n") or die("Write failed\n"); // 數據傳送 向服務器發送消息 while($bunf = socket_read($socket, 1024, PHP_NORMAL_READ)){ echo "BUFF Content:".$bunf; } socket_write($socket,"Action: Logoff\r\nActionID: 123\r\n\r\n"); socket_close($socket); } ?>