Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pkmk

macrumors newbie
Original poster
Mar 30, 2010
6
0
Hi,
I want to bind a port which is already bind by another process. Is there any way to bind the port that is already bind. I used sockopt() function to reuse the port but it not work.

Is there any way to take a port that is bind by anyother process mean we take enforcely the port from other process and use this port for my process. I want to bind the following port no 32005.

I am waiting for your quick response or give me any solution to this problem.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
Hi,
I want to bind a port which is already bind by another process. Is there any way to bind the port that is already bind. I used sockopt() function to reuse the port but it not work.

Is there any way to take a port that is bind by anyother process mean we take enforcely the port from other process and use this port for my process. I want to bind the following port no 32005.

I am waiting for your quick response or give me any solution to this problem.

No, not that I am aware of. That would be a huge security hole if you were allowed to take over the port of another process.

Frankly the only reasons I can think of are malicious. Why do you want to effectively hijack another processes port?

Edit:

The only way to bind to same port is if you bind to a different address, so the other process might be listening on 0.0.0.0:32005 and your process would listen on 1.1.1.1:32005 (for example).
 

pkmk

macrumors newbie
Original poster
Mar 30, 2010
6
0
hi,
thanx for your reply. I am clear this that i am not use this for hijack or any misuse purpose. Now come to problem the problem is i use the UDP socket. And i run two different application. And i want both application bind to same port for sending and receiving data. For this i use sockopt() function this function returns 0. But the bind function returns -1. I use the xcode tools.
The real problem is when i run both application. Then first application is bind successfuly but second application are not bind to same port and return -1.
 

Alkiera

macrumors regular
Mar 11, 2008
109
0
That answer is that you can't do that. A port can be bound by only one application at a time; two applications cannot share a port without having a third app manage the port, and distribute messages to the two applications via some other method.

I think the real issue is why you have two apps listening on the same port? Are you trying to test a client-server app? The client shouldn't need a well-known port... the server should detect what port the client is using from the first UDP packet, and use that report when it replies.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.