# Retrieving bound port/address while listening for connections (InterprocessConnectionServer)

**URL:** https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945
**Category:** General JUCE discussion
**Created:** [August 29, 2017, 4:59am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945 "2017-08-29T04:59:28Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![tsherr](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tsherr/32/2717_2.png) [@tsherr](https://forum.juce.com/u/tsherr)
#### Post date: [August 29, 2017, 4:59am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/1 "2017-08-29T04:59:28Z")

</div>

I’ve created a TCP Server class that implements the InterprocessConnectionServer, creating InterprocessConnection instances for each client that connects. Everything works great, except for one thing: I would like to be able to get the the actual port and address that the InterprocessConnectionServer is bound to, and on which it is listening. I’m creating the server with a port of 0, so there’s no way of knowing (easily) which port was provided by the OS.

It would be great if serverAddress() and serverPort() functions were provided, or alternately, if the InterprocessConnectionServer’s socket member was made protected so I could add those functions to my own TCP Server class.

Thanks!

---

<div class="post-metadata">

### Author: ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)
#### Post date: [August 29, 2017, 10:10am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/2 "2017-08-29T10:10:35Z")

</div>

What are you trying to do?

---

<div class="post-metadata">

### Author: ![tsherr](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tsherr/32/2717_2.png) [@tsherr](https://forum.juce.com/u/tsherr)
#### Post date: [August 29, 2017, 4:28pm UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/3 "2017-08-29T16:28:27Z")

</div>

What do you mean exactly? I thought my initial post was fairly clear.

> I would like to be able to get the the actual port and address that the InterprocessConnectionServer is bound to, and on which it is listening.

---

<div class="post-metadata">

### Author: ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)
#### Post date: [August 29, 2017, 7:02pm UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/4 "2017-08-29T19:02:07Z")

</div>

Sorry, you were perfectly clear. I was just wondering what you were using it for … curiosity rather than helping I’m afraid.

---

<div class="post-metadata">

### Author: ![tsherr](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tsherr/32/2717_2.png) [@tsherr](https://forum.juce.com/u/tsherr)
#### Post date: [August 29, 2017, 7:22pm UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/5 "2017-08-29T19:22:51Z")

</div>

I would be using it to display the listen address and port on the UI, so I know which endpoint the client should connect to. The address isn’t so much of a problem since I can store the address that gets passed to beginWaitingForSocket(), but the port is crucial.

---

<div class="post-metadata">

### Author: ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)
#### Post date: [August 30, 2017, 8:24am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/6 "2017-08-30T08:24:26Z")

</div>

Normally when you put up a server you’d provide a known port number, and ask the server to listen on all interfaces unless there’s some specific (Security probably) reason to have it listen on a specific interface.

I didn’T know it was possible to get bind to listen on a random address… does it work providing 0 as a port number for the server?

---

<div class="post-metadata">

### Author: ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)
#### Post date: [August 30, 2017, 8:25am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/7 "2017-08-30T08:25:32Z")

</div>

Oh - apparently so:  
[https://www.dnorth.net/2012/03/17/the-port-0-trick/](https://www.dnorth.net/2012/03/17/the-port-0-trick/)

---

<div class="post-metadata">

### Author: ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)
#### Post date: [August 30, 2017, 8:27am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/8 "2017-08-30T08:27:38Z")

</div>

From JUCE looks like this is what you’d need, but … the StreamingSocket in the interprocess connection server is private.

```
int StreamingSocket::getBoundPort() const noexcept
{
    return SocketHelpers::getBoundPort (handle);
}
```

---

<div class="post-metadata">

### Author: ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)
#### Post date: [August 30, 2017, 9:08am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/9 "2017-08-30T09:08:45Z")

</div>

[https://github.com/WeAreROLI/JUCE/commit/ff6d01bc254bbaf359b474f53da9a1534b19b90e](https://github.com/WeAreROLI/JUCE/commit/ff6d01bc254bbaf359b474f53da9a1534b19b90e)

---

<div class="post-metadata">

### Author: ![tsherr](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tsherr/32/2717_2.png) [@tsherr](https://forum.juce.com/u/tsherr)
#### Post date: [August 30, 2017, 7:50pm UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/10 "2017-08-30T19:50:22Z")

</div>

Awesome, thanks t0m! Will this be included in the next JUCE update?

---

<div class="post-metadata">

### Author: ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)
#### Post date: [August 31, 2017, 8:41am UTC](https://forum.juce.com/t/retrieving-bound-port-address-while-listening-for-connections-interprocessconnectionserver/23945/11 "2017-08-31T08:41:32Z")

</div>

Yes, or you can get it now by using the `develop` branch from GitHub.
