![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Eternal Student
Join Date: Aug 2008
Location: Lincoln, Nebraska
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 546
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Eternal Student
Join Date: Aug 2008
Location: Lincoln, Nebraska
Posts: 4
Rep Power: 0
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |