The ephemeral ports you mention are used ONLY if  you do not do BIND call
on socket for outgoing connection.
If before doing CONNECT you do BIND,  the local port number will be one
specified in BIND.
Following small program demonstrates it.

#!/usr/bin/python
import socket
import threading


READER_ADDR = ("127.0.0.1", 23008)
WRITER1_ADDR = ("127.0.0.1", 23001)
WRITER2_ADDR = ("127.0.0.1", 23002)


LISTEN_SOCK = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
LISTEN_SOCK.bind(READER_ADDR)
LISTEN_SOCK.listen(3)

DONE = False

class wait_conn(threading.Thread):
    def run(self):
        while not DONE:
            s, a = LISTEN_SOCK.accept()
            print("Incomming connection from: ",  s.getpeername())
            s.close()


t = wait_conn()
t.start()

w1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
w1.bind(WRITER1_ADDR)
w1.connect(READER_ADDR)
w1.close()



w2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
w2.bind(WRITER2_ADDR)
w2.connect(READER_ADDR)
w2.close()

DONE = True

t.join(1.0)
LISTEN_SOCK.close()




2018-06-20 15:19 GMT+02:00 Daniel-Constantin Mierla <
[email protected]>:

> By default, Kamailio is reusing the tcp connection when possible.
>
> Again, about the local port for tcp connections, read more about tcp
> protocol and how a connection is identified (some references about
> ephemeral ports are also there) -- practically it is the tcp stack
> implementation/operating system kernel that does the selection of the local
> port, impossible to ensure it from user space.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/kamailio/kamailio/issues/1532#issuecomment-398745383>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AF36ZSFtK7ZUdmBxJE8DCetWIJGGXa_Lks5t-kvggaJpZM4UAV3q>
> .
>
> _______________________________________________
> Kamailio (SER) - Development Mailing List
> [email protected]
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
>
>
_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to