Longer than expected socket connection time for client
Open
@adam-rocska is already working on this.
Since May 19, 2026.
- Dominant language
- Swift
- Stars
- 1.4k
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
Socket connection times are taking longer than I expected. Ten runs of this simple code results in an average connection time of 0.65 seconds. The the client and "server.local" are both on my wifi network.
import Foundation
import Socket
let MyPySkyXServer = "server.local"
let MyPySkyXPort: Int32 = 1234
do {
let client = try Socket.create()
let startTime = Date()
try client.connect(to: MyPySkyXServer, port: MyPySkyXPort)
print(Date().timeIntervalSince(startTime))
client.close()
}
catch {
print("Error.")
}
While this similar Python script results in average connection times of 0.024 seconds over 10 connects.
import socket
import time
HOST = 'server.local' # The server's hostname or IP address
PORT = 1234 # The port used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
startTime = time.perf_counter()
s.connect((HOST, PORT))
elapsed = time.perf_counter() - startTime
print(elapsed)
s.close()
Am I doing something wrong or is this expected?
Steve
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.