Unix Programming - problems with udp-client-program

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2004 > problems with udp-client-program





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author problems with udp-client-program
Karl Pech

2004-05-18, 12:42 pm

Hallo,

I have tried to write a simple udp-client-program which should behave
like the "write"-program under unix.

I tried to implement the client through non-blocking sockets,
but it didn't work. I don't know what to do.

It would be great if somebody could look at the source-code and comment
on it.

You can find it under http://offskat-game.sf.net .

With best regards
Karl

[P.S. I really want to do it using non-blocking sockets. I know
there must be better solutions for this. But I want to try that first.
Please help me!]
Barry Margolin

2004-05-18, 2:50 pm

In article <c8demi$ofo$1@f1node01.rhrz.uni-bonn.de>,
"Karl Pech" <KarlPech@users.sourceforge.net> wrote:

> Hallo,
>
> I have tried to write a simple udp-client-program which should behave
> like the "write"-program under unix.
>
> I tried to implement the client through non-blocking sockets,
> but it didn't work. I don't know what to do.
>
> It would be great if somebody could look at the source-code and comment
> on it.


Can you be more specific about what didn't work? Nothing obvious stands
out when I look at the code (except that the readline() is never used,
and my_read() is only used by readline(), so I don't understand why
they're in there).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Karl Pech

2004-05-18, 4:47 pm

"Barry Margolin" <barmar@alum.mit.edu> wrote in
news:barmar-CAF175.14473618052004@comcast.dca.giganews.com...
> Can you be more specific about what didn't work? Nothing obvious stands
> out when I look at the code (except that the readline() is never used,
> and my_read() is only used by readline(), so I don't understand why
> they're in there).


Well, the problem is, that once the connection between the two hosts is
established, everything I write on the terminal should appear on the terminal
of the other host and vice versa. But it just doesn't happen.


Regards
Karl

Barry Margolin

2004-05-18, 6:41 pm

In article <c8doe8$f8v$02$1@news.t-online.com>,
"Karl Pech" <KarlPech@users.sf.net> wrote:

> "Barry Margolin" <barmar@alum.mit.edu> wrote in
> news:barmar-CAF175.14473618052004@comcast.dca.giganews.com...
>
> Well, the problem is, that once the connection between the two hosts is
> established, everything I write on the terminal should appear on the terminal
> of the other host and vice versa. But it just doesn't happen.


OK, here are some problems:

You never check n_retcode, the value returned by recvfrom(). You check
errno even though you haven't checked whether n_retcode == -1.

You only call recvfrom() once each time through the loop. If you don't
get anything immediately, you go back to reading a line of input from
the terminal. If the user doesn't type anything, how do you expect to
get back to the next call to recvfrom() to display what the other user
sent?

If that's not it, have you tried running your program under a debugger?
It seems like I have to ask this every time someone posts a "my program
doesn't work" question -- doesn't anyone know how to use debuggers any
more? What ever happened to self-reliance?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Karl Pech

2004-05-19, 5:38 am

"Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
news:barmar-E6A75E.17563918052004@comcast.dca.giganews.com...

Hallo Barry,

> If that's not it, have you tried running your program under a debugger?
> It seems like I have to ask this every time someone posts a "my program
> doesn't work" question -- doesn't anyone know how to use debuggers any
> more? What ever happened to self-reliance?


Unfortunately the only debugger I know under Unix is gdb, and I don't know
how to use it. It's complicated.

Anyway thank you for your help!


Regards
Karl

Barry Margolin

2004-05-19, 5:39 am

In article <c8f0lq$35f$07$1@news.t-online.com>,
"Karl Pech" <KarlPech@users.sf.net> wrote:

> "Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
> news:barmar-E6A75E.17563918052004@comcast.dca.giganews.com...
>
> Hallo Barry,
>
>
> Unfortunately the only debugger I know under Unix is gdb, and I don't know
> how to use it. It's complicated.


I'm not trying to be nasty, but if you can't figure out how to use a
debugger, then programming may not be for you.

Computer programming is complicated.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Karl Pech

2004-05-19, 7:52 am

"Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
news:barmar-A6AF6C.03060119052004@comcast.dca.giganews.com...
Hi Barry,
> [..] if you can't figure out how to use a
> debugger, then programming may not be for you.
> Computer programming is complicated.


You know the rule: "Never ever give up!!! ;))
No matter how complicated a thing is."

Therefore I want to ask you another question.
Can you recommend me a good book for
a beginner in Network-programming under Unix?
You have seen what I have coded, so what kind of book
would be the right one for me? Are there any "Dummies"-type-books
for "Network programming"?

Unfortunately there is also another problem. I have to learn it
fast. (
So this book should also be structured like a lexion (or something
similar.)


Please help me!
I beg you! |)


Regards
Karl.

[P.S.

> Computer programming is complicated.


Yes you're right.

quotes:
> as long as there were no machines, programming was no problem at all; when we had a few weak
> computers, programming became a mild problem, and now we have gigantic computers, programming
> has become an equally gigantic problem. [ Edsger Dijkstra: The Humble Programmer]


> Programmers are always surrounded by complexity. You can not avoid it
> [Hoare]


Barry Margolin

2004-05-19, 5:40 pm

In article <c8fgfu$c51$03$1@news.t-online.com>,
"Karl Pech" <KarlPech@users.sf.net> wrote:

> "Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
> news:barmar-A6AF6C.03060119052004@comcast.dca.giganews.com...
> Hi Barry,
>
> You know the rule: "Never ever give up!!! ;))
> No matter how complicated a thing is."
>
> Therefore I want to ask you another question.
> Can you recommend me a good book for
> a beginner in Network-programming under Unix?
> You have seen what I have coded, so what kind of book
> would be the right one for me? Are there any "Dummies"-type-books
> for "Network programming"?


It seemed to me that you need to learn Unix/C programming in general,
not just network programming.

Anyway, it's not really a "for dummies" type of book, but the best
reference for Unix network programming is "Unix Network Programming,
Volume 1" by W. Richard Stevens.

> Unfortunately there is also another problem. I have to learn it
> fast. (


What did you do, lie on your job application, and actually get a job
that requires the skills you don't really have?

I don't really want to be a jerk like this, but I just don't understand
how people get into this situation when there are lots of unemployed
folks out there who really have the skills.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Karl Pech

2004-05-19, 5:40 pm

"Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
news:barmar-379A6A.11192619052004@comcast.dca.giganews.com...
> It seemed to me that you need to learn Unix/C programming in general,
> not just network programming.


Well, I don't know very much about specific Unix/C-functions, because
I programmed under Windows before. Believe me I know much _much_ more
about the Windows API but I know almost nothing about the Unix API.
It also seems to me that there is no "real" "Unix API" but that you
operate on Unix through Standard C-Library-functions (printf, scanf, gets, ...)
and streams (cout, cin, ...). If it's just printing out something into a file
or onto the screen. Then it's easy and doesn't bother me. But if it gets
more specific ... .

> Anyway, it's not really a "for dummies" type of book, but the best
> reference for Unix network programming is "Unix Network Programming,
> Volume 1" by W. Richard Stevens.


Ok, Thank You!

>
> What did you do, lie on your job application,


No ...

> and actually get a job


No .... =))

> that requires the skills you don't really have?


Yes, I don't have these skills but I want to learn them, because ...
I'm an informatics-student(!) in my second semester. In the first
semester the already had some programming courses but not(!) about Network Programming
We had to solve more theoretical problems which included concepts like
recursion (backtracking ...), iteration, dynamically-linked-lists, stacks, binary trees,
.... . You don't have to know the details about Unix to solve problems which use
these concepts. Actually I always solved tasks for these concepts under Windows (since
VC++ 6 has a more comfortable built-in debugger then gdb)
und then just demonstrated it under Unix.
For those tasks I didn't have to know more about Unix than the usual printf/scanf/cout/cin-
stuff. ;)

> I don't really want to be a jerk like this, but I just don't understand
> how people get into this situation when there are lots of unemployed
> folks out there who really have the skills.


Yes, I don't understand that too. |)))
[But I think these people didn't really study for their work.]


Regards
Karl


joe@invalid.address

2004-05-19, 5:40 pm

"Karl Pech" <KarlPech@users.sf.net> writes:

> "Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
> news:barmar-379A6A.11192619052004@comcast.dca.giganews.com...
>
> Well, I don't know very much about specific Unix/C-functions,
> because I programmed under Windows before. Believe me I know much
> _much_ more about the Windows API but I know almost nothing about
> the Unix API. It also seems to me that there is no "real" "Unix
> API" but that you operate on Unix through Standard
> C-Library-functions (printf, scanf, gets, ...) and streams (cout,
> cin, ...).


Those are C++ streams :-)

> If it's just printing out something into a file or onto the
> screen. Then it's easy and doesn't bother me. But if it gets more
> specific ... .


Seems to me that it's much the same as anything else. Special purpose
APIs exist on all platforms so that programmers don't have to rewrite
code that's been written already. I did some Windows programming once
long ago, and felt the same kind of dismay you describe here. There
were so many special purpose APIs that had to be learned to do
anything non-trivial. Personally, I think Unix is simpler, but that's
another thread :-).

In addition to the Stevens books that Barry recommended, the POSIX/SUS
web site also has good information. Not nearly as extensive or
complete as Stevens, but the man pages are pretty good, and contain
cross references via hyperlinks.

http://www.opengroup.org/onlinepubs/009695399/

gets you access to the whole thing.

Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
Barry Margolin

2004-05-19, 8:36 pm

In article <c8g2eh$iq1$05$1@news.t-online.com>,
"Karl Pech" <KarlPech@users.sf.net> wrote:

> "Barry Margolin" <barmar@alum.mit.edu> schrieb im Newsbeitrag
> news:barmar-379A6A.11192619052004@comcast.dca.giganews.com...
>
> Well, I don't know very much about specific Unix/C-functions, because
> I programmed under Windows before. Believe me I know much _much_ more
> about the Windows API but I know almost nothing about the Unix API.
> It also seems to me that there is no "real" "Unix API" but that you
> operate on Unix through Standard C-Library-functions (printf, scanf, gets,
> ...)
> and streams (cout, cin, ...). If it's just printing out something into a file
> or onto the screen. Then it's easy and doesn't bother me. But if it gets
> more specific ... .


There certainly *is* a Unix API: I/O functions like open(), read(),
write(), and close(); memory management functions like brk(); process
management functions like fork() and execvp(); and lots more.

Anyway, the problems I saw in your little sample program did not seem to
be at all specific to the Unix stuff.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com