Results 1 to 5 of 5
Hi there.
I'm new to socket programming and have a question about it...
I wrote, with the help of a guide book, a code for a simple server, and another ...
- 03-11-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 2
Help with server/client using C
Hi there.
I'm new to socket programming and have a question about it...
I wrote, with the help of a guide book, a code for a simple server, and another one for a client.
Q: Can i run the server app in Console and the client app in another Console? I mean, on the same machine? should they communicate? the client is trying to connect to my own IP..
If so, i'm having problems with connect() function.. but first I think i should find out if it's possible..
btw, I'm using C language..
Thank you very much,
giora.
- 03-12-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Certainly. People do this (client and server on same system) all the time. The server uses listen() + accept(), the client uses connect(). Spend some $$ and get "Internetworking with TCP/IP, Volume III, Client-Server Programming and Applications" by Comer and Stevens (see Amazon.com). Prentice-Hall is (was) the publisher. Here is the Amazon.com link: Amazon.com: Internetworking with TCP/IP, Vol. III: Client-Server Programming and Applications, Linux/Posix Sockets Version (9780130320711): Douglas E. Comer, David L. Stevens: Books
Note that I paid $50 USD for it almost 20 years ago and it is only $67.50 USD today - a bargain at 2x the price!
Trust me, it is one to keep on your book shelf. I have all three volumes, but that is probably overkill for you at this time.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 03-12-2011 #3Just Joined!
- Join Date
- Mar 2011
- Posts
- 2
Thanks Rubberman..
I guess that my problem is the connect() function that for some reason returns an error (-1) ...
thanks again.
- 03-12-2011 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Make sure all your setup works properly before you call connect(). Maybe one of those calls also returned an error and you didn't detect it?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-21-2011 #5Just Joined!
- Join Date
- Apr 2011
- Posts
- 19
netstat
You can do a netstat -an to check if your server program has opened a socket in listen mode.
I tend to use
netstat -an | grep 7000
if I opened a server port on port number 7000. You should see a line line
tcp 0 0 0.0.0.0:7500 0.0.0.0:* LISTEN
if it worked. It could also be your trying to open a port that is already in use. As rubberman
suggested, check those return codes from listen and socket.


Reply With Quote