how to send custom frame in socket programming
hi dudes !
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.
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.
if you are trying to send & receive non-ip frames, it can be done using raw sockets. For a starter,
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.
I always compile C code with the -std=gnu99 option.
|All times are GMT -5. The time now is 10:44 PM.|