Im having trouble understanding what/why the following is happening
The server sends the following 6 bytes data to the client.
Send - Server
The client reads only 3 bytes of the available 6 bytes sent.Code://Send - Server int RetVal; char pd; //Packet Data pd = 'A'; pd = 'B'; pd = 'C'; pd = 'D'; pd = 'E'; pd = 'F'; RetVal = send(remoteConnection->clientsocketfd,pd,6,NULL);
Recv - Client
OutputCode://Recv - Client char rd; //Received Data recv(remoteConnection->socketfd,(char*) rd,3,NULL); printf("\n0 Byte = %c",rd); printf("\n1 Byte = %c",rd); printf("\n2 Byte = %c",rd); printf("\n3 Byte = %c",rd); printf("\n4 Byte = %c",rd); printf("\n5 Byte = %c",rd); printf("\n6 Byte = %c",rd); printf("\n7 Byte = %c",rd);
The problem is when the received data is read its the last 3 bytes of data.Code://Output 0 Byte = D 1 Byte = E 2 Byte = F 3 Byte = ¶ //Null 4 Byte = ¶ //Null 5 Byte = ¶ //Null 6 Byte = ¶ //Null 7 Byte = ¶ //Null
I was expecting it to be the first 3 bytes to be 'A','B' and 'C' of the data that was sent
not the last 3 which is 'D','E' and 'F'.
What Iím trying to do is as described in Beej's Guide to Network Programming Chapter 6.5. Son of Data Encapsulation
Where the length of a packet is put as a header as a first byte. The receiver receives the first few bytes then knows from the header how much more bytes he needs to read to get the full packet.
But by receiving the last few bytes instead of the first few Im having trouble to do this because the packet length (which is the first byte) isnít read.
By the way im using WinSocks