You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
While this similar Python script results in average connection times of 0.024 seconds over 10 connects.
Am I doing something wrong or is this expected?
Steve
The text was updated successfully, but these errors were encountered: