所以这真的是一个第一个导致第二个的两个部分问题。

我正在使用PHP服务器项目,我有点困惑我可以创建套接字的所有不同方式。我设法使用新方法创建三个套接字。如果有的话,有人知道这三种方法之间的根本区别吗?

方法1使用'socket_create'

$Socket1 = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
socket_bind($Socket1, $LocalIP, $LocalPort)
socket_connect($Socket1, $DestIP, $DestPort)
//Method 1 Read
socket_read($Socket1)
//Method 1 Write
socket_write($Socket1, $WriteMsg, strlen($WriteMsg))
.

方法2使用'fsockopen'

$Socket2 = fsockopen($Server, $Port)
//Method 2 Read
fgets($Socket2)
//Method 2 Write
fputs($Socket2, $PutMsg, strlen($PutMsg))
.

方法3使用'stream_socket_client'

$Socket3 = stream_socket_client('tcp://'.$DestIP.':'.$DestPort)
//Method 3 Read
stream_socket_recvfrom($Socket3, $RecSize)
//Method 3 Write
stream_socket_sendto($Socket3, $SendMsg)
.

虽然我不明白我正在探索所有三种选择来控制TCP窗口大小的方法。我正在尝试将数据包推向客户端,通过我的LAN具有1460字节的数据有效载荷,并且在审阅数据包之后,我的数据包的TCP数据部分始终在1448字节处切换。任何想法?

提前感谢!

有帮助吗?

解决方案

You can't control the actual amount of data received at a time. TCP is a streaming protocol. It presents a byte-stream API to the application. You just have to be prepared to read and re-read until you have got what you want.

其他提示

You should be able to do this with the socket_set_option command (where options are documented in the socket_get_option command):

$Socket1 = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
// send window
socket_set_option($Socket1, SOL_SOCKET, SO_SNDBUF, 1460);

Just be sure to call it right after socket_create. If you need the receive window modified:

socket_set_option($Socket1, SOL_SOCKET, SO_RCVBUF, 1460);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top