I'm a BSD Socket beginner and I would like to make a small networking program written in C.

I've read many instructional articles and I haven't found a example how to send/receive a non-char - string sending everywhere. I mean, I thought about sending some various structures as "frames". Which would contain: username, filename, data, timestamp, etc. for instance.

The problem is how should I receive the various structures /"frames"/ by recv() func?

Can anybody give me an advice with this? Am I thinking right? I would really appreciate any help with sending a non-string-only data.

7 Years
Discussion Span
Last Post by yuri1969

The easiest way is the functionality in the XDR library(eXternal Data Represention) or if your not familiar then you could pass non c-string data by passing the start address and the length...Like this.

unsigned int mydata = 1234;

write(clientfd, &mydata, sizeof(mydata));

Please note, you cannot pass pointers and expect the receiver to use them without failure....You must pass the data that the pointer points to..

Edited by gerard4143: n/a


Ok, so I'm leaving my struct-based date idea. I'll pass the data directly in a sequence of write().

Thank you for the reply.


Too difficult for a beginner as me.

Edited by yuri1969: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.