Domanda

Quindi questa è davvero una domanda a due parti con il primo conduttore al secondo.

Sto lavorando su un progetto PHP Server e sono un po 'confuso con tutti i diversi modi in cui posso creare una presa.Sono riuscito a creare tre prese ciascuna utilizzando un nuovo metodo.Qualcuno conosce la differenza fondamentale tra questi tre metodi se qualunque?

Metodo 1 Uso '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))
.

Metodo 2 Uso 'Fsockopen'

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

Metodo 3 Uso '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)
.

Anche se non capisco la differenza che stavo esplorando tutte e tre le opzioni in cerca di un modo per controllare le dimensioni della finestra TCP.Sto cercando di spingere un pacchetto su un cliente sulla mia LAN che ha un carico utile dei dati di 1460 byte e dopo aver esaminato una cattura di pacchetti La parte dei dati TCP del mio pacchetto è sempre tagliata a corto a 1448 byte.Qualche idea?

Grazie in anticipo!

È stato utile?

Soluzione

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.

Altri suggerimenti

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top