UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » How to reuse port on linux

#1 2012-10-29 04:37 PM

testparam
Member
Registered: 2012-10-29
Posts: 2

How to reuse port on linux

Hey,all
How to reuse port on linux,Supports TCP connections?

Examples of this?

Offline

#2 2012-10-29 09:31 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to reuse port on linux

What do you mean exactly by "reuse port"?  Do you mean be able to bind() to a port which still has old lingering TIME_WAITs on it?  If so, set the SO_REUSEADDR sockopt...  If you're looking for a SO_REUSEPORT-style sharing of port#'s between multiple processes, I don't think Linux supports it...  (And, it's not generally a sane idea either...)

Offline

#3 2012-10-30 09:55 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: How to reuse port on linux

You can have multiple processes using the same port number, but on different interfaces.

Offline

#4 2012-10-30 11:42 AM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to reuse port on linux

Yep, true enough, as long as you bind each to a specific IP and don't have any bound to INADDR_ANY...  I'm still not sure if that's even what the question is about, though...

Offline

#5 2012-10-30 12:00 PM

testparam
Member
Registered: 2012-10-29
Posts: 2

Re: How to reuse port on linux

I mean is, I have a linux server running with httpd service iptables only allow open port 80, so, I want my program and the httpd 80 ports coexistence, shared this port, and is the state of TCP connections, only one network interface eth0.

port 80,listen httpd and my program

Offline

#6 2012-10-30 07:22 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to reuse port on linux

No, you can't do that...  It doesn't really make any sense if you think about what it entails...  How on Earth would you distinguish traffic destined for your program vs. that destined for httpd?  That's what separate port numbers are for!

Why can't you just change the iptables rules to allow some other port to receive traffic as well?

Or, write your server as some kind of web-based service, so that you can actually reach it through httpd...

Offline

  • Index
  • » C
  • » How to reuse port on linux

Board footer

Powered by FluxBB