Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Aug 31st, 2008, 5:14 PM   #1
BigBeagle
Eternal Student
 
BigBeagle's Avatar
 
Join Date: Aug 2008
Location: Lincoln, Nebraska
Posts: 4
Rep Power: 0 BigBeagle is on a distinguished road
Can I have an incoming and outgoing socket on the same port number?

Hello,

Since this is really a language agnostic question, I thought I'd ask it in the Other section. Anyway, what I'm trying to do is write a program to act as a sort of web-filter. It would listen for http requests, and then forward those requests to an external server. It would then take what it gets back, edit it, and return it to the original client.

My idea of how to do this is to have a socket listening on tcp port 80, and upon getting a connection, and getting the client's message, open another socket on port 80 to the external server. My question is whether this is legal, having incoming and outgoing connections on the same port? Or do I have to rethink how I'd go about this? Thanks.

PS. On the off chance it does matter, I'm using Python with it's socket module under Linux.
BigBeagle is offline   Reply With Quote
Old Sep 1st, 2008, 11:30 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 546
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Can I have an incoming and outgoing socket on the same port number?

I don't see why not. Just close the first socket connect before opening it again for someone else. That means it will cut off communication with the original sender, but its not a big deal if no further communication is necessary.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Old Sep 2nd, 2008, 1:01 AM   #3
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Re: Can I have an incoming and outgoing socket on the same port number?

You can listen on one socket under port 80 and still open another socket on port 80 for a different address. The connection is not just defined by the port, but also by the IP address.
Otherwise you could never browse the web when you had a local web server.
The Dark is offline   Reply With Quote
Old Sep 2nd, 2008, 5:24 PM   #4
BigBeagle
Eternal Student
 
BigBeagle's Avatar
 
Join Date: Aug 2008
Location: Lincoln, Nebraska
Posts: 4
Rep Power: 0 BigBeagle is on a distinguished road
Re: Can I have an incoming and outgoing socket on the same port number?

Okay, thanks. I'll try going with this and see how it goes.
BigBeagle 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
sockets problem haba C 10 Nov 19th, 2007 2:03 AM
sockets hbe02 C++ 1 Jun 1st, 2006 8:22 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:59 AM.

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