문제

이것은 정말로 첫 번째로 이어지는 두 부분의 질문입니다.

PHP 서버 프로젝트에서 작업하고 있습니다. 나는 소켓을 만들 수있는 모든 여러 가지 방법으로 조금 혼란 스럽습니다.새 메소드를 사용하여 각각 3 개의 소켓을 만들 수있었습니다.누구 든지이 세 가지 방법의 근본적인 차이를 알고 있습니까?

방법 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 창 크기를 제어하는 방법을 찾는 방법을 찾는 세 가지 옵션을 모두 탐색했습니다.1460 바이트의 데이터 페이로드가있는 LAN을 통해 클라이언트를 클라이언트로 밀어 넣으려고하고 패킷 캡처를 검토 한 후 내 패킷의 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