Hi,
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.

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 6 Years Ago 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 6 Years Ago by yuri1969: n/a

This article has been dead for over six months. Start a new discussion instead.