Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 29th, 2005, 10:28 AM   #1
linuxpimp20
Hobbyist Programmer
 
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4 linuxpimp20 is on a distinguished road
simple exercises to play around with sockets?

hi. i've been reading about socket programming lately and want to get my hands dirty. Is there any exercises i could to to mess around with them? I don't have two linux boxes so i can't make a real connection but is it possible to connect back to myself connection 127.0.0.1? In that case would it be difficult to tell if i was successful or not? thanks for any replies in advance.
linuxpimp20 is offline   Reply With Quote
Old Aug 29th, 2005, 10:30 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
yap, you can connect to yourself via 127.0.0.1, but make sure you don't connect on the same port
Polyphemus_ is offline   Reply With Quote
Old Aug 29th, 2005, 10:46 AM   #3
linuxpimp20
Hobbyist Programmer
 
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4 linuxpimp20 is on a distinguished road
to make sure im doing it right would it be just as simple has having two shells opened and sending the data to standard input?
linuxpimp20 is offline   Reply With Quote
Old Aug 29th, 2005, 11:05 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Have two shells open... one for the client and one for the server. Use 127.0.0.1 has the IP for both... just send and receive on unique ports... do not have them be the same and don't have them be a port that is already in use by a known service (ie httpd=80).
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 29th, 2005, 11:36 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Infinite Recursion
just send and receive on unique ports...
Eh? So far as I know, you just need a unique port for each listener. You can have multiple programs sending data to the same port/IP address.
Arevos is offline   Reply With Quote
Old Aug 29th, 2005, 11:43 AM   #6
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by Arevos
Eh? So far as I know, you just need a unique port for each listener. You can have multiple programs sending data to the same port/IP address.
yes, you can send data to the same port/IP address idd. Think of a webserver, it receives multiple requests on the same port.
The point we are mentioning though, is the client can't use the same port as the server on the same system.
Polyphemus_ is offline   Reply With Quote
Old Aug 29th, 2005, 12:26 PM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Polyphemus_
The point we are mentioning though, is the client can't use the same port as the server on the same system.
So you're saying that the client doesn't just connect to the server, it also listens for incoming connections, à la FTP?
Arevos is offline   Reply With Quote
Old Aug 29th, 2005, 12:33 PM   #8
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by Arevos
So you're saying that the client doesn't just connect to the server, it also listens for incoming connections, à la FTP?
Uhm, wel.. nope Just that two programs on the same system can't use one port at the same time (maybe with some kernel hacking, but you get the point ).
Polyphemus_ is offline   Reply With Quote
Old Aug 29th, 2005, 12:49 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
I think you're getting confused with how TCP/IP works, or I'm just not understanding what you're getting at. Binding to a port only matters when you're listening. So, for instance, I have a HTTP server listening on port 80 on my computer. I couldn't start another HTTP server and tell it to listen on port 80, because that's already taken.

But I can point multiple browsers to my one HTTP server. I can have two clients connected to the same port at the same time on the same system. So your assertion that "the client can't use the same port as the server on the same system" doesn't make sense to me, because clients typically don't need to bind to a port. Only protocols like FTP, where the client also has to listen to incoming connections from the server, would this make any sense at all.
Arevos is offline   Reply With Quote
Old Aug 29th, 2005, 12:59 PM   #10
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by Arevos
I think you're getting confused with how TCP/IP works, or I'm just not understanding what you're getting at. Binding to a port only matters when you're listening. So, for instance, I have a HTTP server listening on port 80 on my computer. I couldn't start another HTTP server and tell it to listen on port 80, because that's already taken.

But I can point multiple browsers to my one HTTP server. I can have two clients connected to the same port at the same time on the same system. So your assertion that "the client can't use the same port as the server on the same system" doesn't make sense to me, because clients typically don't need to bind to a port. Only protocols like FTP, where the client also has to listen to incoming connections from the server, would this make any sense at all.
really? weird.. last time i tried i got an error the port was already in use.. and i didn't have to give arguments whether it was for input or output. maybe a java thingy?

I still have to learn much
Polyphemus_ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC