Re: Read/Write socket Problem
From: Xarky (bernardpace_at_yahoo.com)
Date: 05/12/05
- Next message: Pat Ford: "defined but not used messages"
- Previous message: Måns Rullgård: "Re: Determining endian?"
- In reply to: David Schwartz: "Re: Read/Write socket Problem"
- Next in thread: James Antill: "Re: Read/Write socket Problem"
- Reply: James Antill: "Re: Read/Write socket Problem"
- Reply: Wayne C. Morris: "Re: Read/Write socket Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 May 2005 06:04:28 -0700
"David Schwartz" <davids@webmaster.com> wrote in message news:<d5fscf$1m8$1@nntp.webmaster.com>...
> "Xarky" <bernardpace@yahoo.com> wrote in message
> news:bc42e1a.0505060444.94a7150@posting.google.com...
>
> The problem is that you do not understand what you are sending and
> receiving at the byte level. You need to make sure your receiver expects to
> get and understands the same *bytes* the sender is supposed to send.
>
> DS
Hi,
Regarding the same problem again.
I am always writing 3 bytes from client, reading 3 bytes from server,
writing 1 byte from server and reading one byte from client.
The problem appears when the number entered is greater or equal to 10.
The bytes that I am sending should be '10\0'. 10 was taken as an
example
Now when I send a number smaller than 10, 2 bytes seems to be
transfered (9\0), while I am reading 3 bytes.
Can you please give me further explanation of the solution, because I
can't understand. Below is the main code that is being used for
communication.
Thanks in Advance
*** Server side ***
char givenNo[3];
char option;
do
{
bzero(&givenNo, sizeof(givenNo));
data = read(client_socket, &givenNo, sizeof(givenNo));
...
bzero(&option, sizeof(option));
option = 'W'; or option = 'G'; or option = 'S';
...
data = write(client_socket, &option, sizeof(option));
} while(...);
*** Client side ***
char guess[3];
char reply;
do
{
bzero(&guess, sizeof(guess));
getline(guess, 3);
data = write(socket_id, &guess, sizeof(guess));
bzero(&reply, sizeof(reply));
data = read(socket_id, &reply, sizeof(reply));
}
while(...);
- Next message: Pat Ford: "defined but not used messages"
- Previous message: Måns Rullgård: "Re: Determining endian?"
- In reply to: David Schwartz: "Re: Read/Write socket Problem"
- Next in thread: James Antill: "Re: Read/Write socket Problem"
- Reply: James Antill: "Re: Read/Write socket Problem"
- Reply: Wayne C. Morris: "Re: Read/Write socket Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|