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'm writing a program which uses sockets and now I want to start testing if actually works
I wrote a small test program which opens a connection to "127.0.0.1" and transmits two messages to my program.
Test program:
1. socket()
2. connect()
3. send(msg1)
4. send(msg2)
the accept/connect part completes without any problems but recv() returns 0 before the test program transmits it's 1st message. As I understand this means that the socket has disconnected.
Both send() returns -1.
Isn't it possible to run both my program and test program on the same pc or do I need to the setup differently?
Ok, I'll try that. Thanks!
BTW:
I have a struct:
typedef struct {
char msg_id;
long length;
} msg_t;
sizeof(msg_t.msg_id) = 1
sizeof(msg_t.length) = 4
sizeof(msg_t) = 8
I guess this is because my OS is 32 bit, but can I (easily) avoid having to send 8 bytes, and instead just the 5 I need?
(Without making a send-function for every message struct I have.)
I'd be tempted to use line buffered ascii data to start with,
at least until you understand how sockets operate.
if they are readable messages why not transmit them as such.
sockets aren't difficult, they are just awkward and confusing at times.
you see a lot of inet protocols are text based, SMTP and HTTP to name but two.
try nc localhost 25 and play with the mail server for instance. the advantage is
you can debug easy using tools like nc.
An XMMS plugin to edit the playlist and control playback over a Wifi connection.
(A PSP connected to a PS3 with Ubuntu.)
I want to display album pictures so I need to send binary.
so quite a complex protocol then?
but using an ascii protocol does not preclude sending binary data.
I've done it myself.
Not that I'm trying to dissuade you but if it's a complex protocol
not human readable, with lots of messages you'll need a suite of functions
to help debug it too.
if you are sendin a TCP packet with a message in it why not make it
readable.
Last edited by bigearsbilly; 07-26-2007 at 08:41 AM.
It's not to bad
And I found my error. I thought connect() returned a new socket like accept() does. Whoops!
I only have around 20 messages and only 3-4 complex ones, so I think I'll stick with the binary.
Thank you for your help and suggestions, though! (It's always nice to learn a new linux "command" )
I'll try to remember to post an update on this thread.
And I'll upload it the XMMS site, when it's done.
(Hopefully in a couple of weeks depended on this crappy weather )
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.