Send integer value by "send( )" 
Author Message
 Send integer value by "send( )"

Hello,

I just learn unix network programming(and  working... :(  ) and send some
data by send() function.

There is no problem send (void *)  type data using send() function.

But.. how can I transfer int type value?

For example

unsigned int uiLen = 372;
int *pLen = &uiLen;

send(client_fd, (void *)pLen, sizeof(uiLen), 0);

The value transfered at server is 372, but received value by java client is
just 116.

Is there any problem using "send()" function?

Environment

Server : FreeBSD(x86), c language
Client  : Java
protocol : TCP/IP



Sun, 12 Sep 2004 15:54:17 GMT  
 Send integer value by "send( )"

Quote:
> Hello,
> I just learn unix network programming(and  working... :(  ) and send some
> data by send() function.
> There is no problem send (void *)  type data using send() function.
> But.. how can I transfer int type value?

send() is not an ISO C function and therefore your question is off-topic
for comp.lang.c. I suggest you ask in comp.unix.programmer.

Quote:
> For example
> unsigned int uiLen = 372;
> int *pLen = &uiLen;
> send(client_fd, (void *)pLen, sizeof(uiLen), 0);
> The value transfered at server is 372, but received value by java client is
> just 116.
> Is there any problem using "send()" function?

<OT>
Not necessarily. Your C program and your Java program might be using
different byte-by-byte encodings of the int values. To be safe, send and
read one byte at a time, and then build the int values from the bytes.
</OT>

Quote:
> Environment
> Server : FreeBSD(x86), c language
> Client  : Java
> protocol : TCP/IP

If you need to state which operating system you are using, there's a
good chance you are off-topic for comp.lang.c.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"Hasta la Vista, Abie!"
   - Bart Simpson



Sun, 12 Sep 2004 16:29:11 GMT  
 Send integer value by "send( )"

Quote:

> I just learn unix network programming(and  working... :(  ) and send some
> data by send() function.
> There is no problem send (void *)  type data using send() function.
> But.. how can I transfer int type value?
> For example
> unsigned int uiLen = 372;
> int *pLen = &uiLen;
> send(client_fd, (void *)pLen, sizeof(uiLen), 0);
> The value transfered at server is 372, but received value by java client is
> just 116.
> Is there any problem using "send()" function?

We really can't help you with network programming or your send()
function here, because neither networks nor a send() function are
anywhere in the definition of C or its standard libraries.  Howerver,
372-116 == 256, which suggest that your function does not operate on
values greater than 255 (0377 or 0xFF).  This suggests that it operates
on unsigned chars, not unsigned ints.  If your unsigned char is 8 bits,
they could never have a value 372.  Perhaps on the receiving end you are
not an the incoming values, and the next one might just hold the missing
bit (0001 or 0x01).

--
It is better that the grammarians should chide us
than that the people should not understand us.
  - St. Augustine



Sun, 12 Sep 2004 18:03:42 GMT  
 Send integer value by "send( )"

Quote:
> unsigned int uiLen = 372;
> int *pLen = &uiLen;

> send(client_fd, (void *)pLen, sizeof(uiLen), 0);

> The value transfered at server is 372, but received value by java client is
> just 116.

> Is there any problem using "send()" function?

Look for htonl(3) and ntohl(3) functions. BTW, I'm not sure this
question has anything in common with the C language itself.

Cheers,
Sergey



Sun, 12 Sep 2004 18:07:18 GMT  
 Send integer value by "send( )"

Quote:

> Hello,

> I just learn unix network programming(and  working... :(  ) and send some
> data by send() function.

> There is no problem send (void *)  type data using send() function.

> But.. how can I transfer int type value?

> For example

> unsigned int uiLen = 372;
> int *pLen = &uiLen;

> send(client_fd, (void *)pLen, sizeof(uiLen), 0);

> The value transfered at server is 372, but received value by java client is
> just 116.

> Is there any problem using "send()" function?

> Environment

> Server : FreeBSD(x86), c language
> Client  : Java
> protocol : TCP/IP

well,

it's something that depends on the machine.
lets make it clear.
once u asign 372 to some unsigned int variable, it is stored in following format
higher byte         lower byte
00000001             01110100

right. Now observe that the lower byte's magnitude is 116.

now i strongly suspect that ur server and client are of diffrent architectures.
Hence the value which was 372 in server is treated as 116 in the client machine.
                                    thats all
                                        raghavendra.sm



Sun, 12 Sep 2004 19:30:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Send signal to "Com port", How?

2. Sending a ".csv" file

3. Newbie question - Sending "directed" events

4. How to Send "NM_RETURN" ather Apprication

5. command line "Send Mail" app

6. detect "net send " popup

7. sending "atat" to com port

8. How to send "keystrokes"?

9. "Send to - IR Receiver"

10. empty "Send To" menu item

11. implementing a "send email"

12. Sending a "ON_BN_CLICKED,"

 

 
Powered by phpBB® Forum Software