ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to send a frame from client/server and then makes some checks on the frame type. can some body tell me how to send it.
frame will contain 3 things: type, length, and data
i created a structure, place some data in the structure but the problem is how to send this structure. will its values be accessed on the client and through which variable. will i have to create another instance of the structure in client or what ?
i have also to make check on type field, that if this type of frame then do this work and if this type then do that.
Help is needed from the programmers to please mention the method and little code example will be appreciated.
Have you looked into datagram sockets? You should take a look at info libc and find the section on sockets. As far as transmitting structures: they have to be 100% self-contained, i.e. no pointers, otherwise the receiving end will be looking for the actual data within its own memory space. You also might run into endian-ness or register size problems if you're using two different architectures. That's a lot to take into account, so I'd consider sending text, e.g. XML. Of course, I don't know if that will suit your purpose.
ta0kira
PS Do you mean a frame "proper"? That is at the kernel level, which is generally more work than it's worth unless you're inventing a new protocol, such as a replacement for TCP or UDP. I can't help you with that! Take a look at less /etc/services; I doubt you'll find many that aren't either!
PPS The sending and receiving setup takes 10+ lines on either end; not just a single method. It's a lot of work if you've never dealt with it!
P3S I've been assuming C/C++, but that's because people generally specify a language if it isn't one of those when asking this type of question. I'm also assuming *nix, but that isn't a requirement of the forum.
i want to establish some client/server communication in C
the connection was established sending a welcome message from the server to the client.
now the client would like to request for some file from the server.
the frame would contain 3 fields, one is type, 2nd is length and 3rd is payload which in this case would be file name.
now the problem is how to send all these three information using a single structure and then how i will display them on the server, that the client has requested for this file, its size is this.
I don't think a structure is really necessary in your situation. Concerning the data you want to send to the server, consider packing it into a char buffer.
For example:
PHP Code:
...
int type = 1; char* filename = "/etc/hosts"; size_t frameSize = sizeof(type) + sizeof(frameSize) + strlen(filename);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.