0

im trying to send a large packet ( 9170 bytes ) using fwrite to a tcp server

            fwrite($this->_socket, $data);

Problem is it send 8192 first then send the left 978 bytes and i want to decrease the amount sent from 8192 to 1444 for each time it is sent

3
  • 1
    What is the actual problem you are trying to solve? Commented Jan 31, 2012 at 10:25
  • Server does not accept more than 1444 bytes at a time Commented Jan 31, 2012 at 14:51
  • The client doesn't have to arrange its transmissions to meet the server's reception requirements. The TCP layer will do that. The client can send 9,840 bytes and if the server only accepts 1444 bytes at a time, it will still get all of them. Commented Jan 31, 2012 at 20:33

4 Answers 4

1

The TCP layer will do this, you don't have to. If you write 9,880 bytes and the server only tries to read 1,444 of them, it will get up to the first 1,444 bytes. The next time the server tries to read, it will get the next byte or bytes.

The client doesn't have to arrange its transmissions to meet the reception requirements of the server. The TCP layer's flow control will handle this automatically.

You're solving a non-problem.

Sign up to request clarification or add additional context in comments.

Comments

0

According to fwrite documentation the optional third parameter of fwrite is length. It denontes maximum number of bytes that will be sent before end of string is reached. Won't this be the solution to your problem?

See the examples in comments below the documentation, they contain examples how to use fwrite with length.

2 Comments

unfortunately it stops after length and does not split it
Just execute the fwrite in a loop, sending next portion of data in each iteration.
0

$data is a string right ? You can split using substr() and then just keep sending.

Comments

0

In that case, just send 1444 bytes and wait for a user-level acknowledgement message from the the server. That will give the appearance of sending 1444 bytes at a time. It will also be painfully slow.

The root problem is that TCP is not capable of sending messages any longer than one byte - it streams bytes.

Add a protocol on top of TCP that can send messages.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.