What I am asking is, how much does opening a TCP socket val socket: Socket("198.51.100.1", 9999)
always whenever you are going to send an request socket.outputstream().write("Hello World!".toByteArray())
and then closing it socket.close()
impact the performance of a program/an app? I am developing an app, which always opens a new socket using coroutines, however, the problem was at the end device, the ports were starting at 53000 (or something like that), so the ports for every socket would fill up very quickly.
I am asking, how would this impact performance? Thanks.
TCP is very slow to initialize, due to the anti-congestion algorithm. Your concern should not be the ports (unless you are making a lot of requests and leaking connections), but the initialization time. If you can use keepalive sockets, that is much preferable.