Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Longer than expected socket connection time for client #188

Open
SmackTO opened this issue May 31, 2020 · 1 comment
Open

Longer than expected socket connection time for client #188

SmackTO opened this issue May 31, 2020 · 1 comment

Comments

@SmackTO
Copy link

SmackTO commented May 31, 2020

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

@SmackTO
Copy link
Author

SmackTO commented May 31, 2020

Some more info: Xcode 11.5 and Python 3.7.7 on MacOS 10.15.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant