phpsocketstcpmss

PHP Socket Types and TCP Window Size


So this is really a two part question with the first leading to the second.

I'm working on a PHP server project and I'm a bit confused with all the different ways I can create a socket. I've managed to create three sockets each using a new method. Does anyone know the fundamental difference between these three methods if any?

Method 1 using '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))

Method 2 using 'fsockopen'

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

Method 3 using '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)

Although I don't understand the difference I was exploring all three options looking for a way to control the TCP Window Size. I'm trying to push a packet to a client over my LAN that has a data payload of 1460 bytes and after reviewing a packet capture the TCP data portion of my packet is always cut short at 1448 bytes. Any ideas?

Thanks in advance!


Solution

  • 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.