-
Notifications
You must be signed in to change notification settings - Fork 195
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
ambiguous reference to member 'connect(to:port:) #19
Comments
Can I see a bit more code? Thanks. |
Sorry for the trouble. It was my mistake. For what it worth here are my simple examples: Server: import Socket var soc = try Socket.create() try soc.listen(on: 9999) var srv = try soc.acceptClientConnection() print("(data!)") try srv.write(from: msg) srv.close()Client: // SimpleClient import Socket var cln = try Socket.create() let host = "localhost" //let sig = try Socket.Signature(socketType: .stream, proto: .tcp, hostname: host, port: port) try cln.connect(to: host, port: port) try cln.write(from: msg) var data = try cln.readString() print("(data!)") cln.close() |
I just tried to reproduce your problem... It looks like your not using the connect API correctly... That API doesn't return anything. It just returns if successful and will throw an exception if there's an error. Below is a little test program I cobbled together to try to reproduce your problem. Have a look an see if this helps you in solving your problem. import Socket
public func run() {
do {
let socket = try Socket.create()
try socket.connect(to: "localhost", port: 9999)
} catch let error {
guard let socketErr = error as? Socket.Error else {
print("Unknown error...")
return
}
print("Error reported: \(socketErr.description)")
}
}
run() This little snippet compiles cleanly and when run throws the appropriate error since there's nothing listening on the specified port. |
No problem... Glad you found it. Let me know if you have anymore questions. In the meantime, I'm going to close this issue. |
I have problem in compiling a simple client socket example:
swift build
Compile Swift Module 'SimpleClient' (1 sources)
/home/sharil/swift_projects/NetProClient/Sources/main.swift:13:15: error: ambiguous reference to member 'connect(to:port:)'
var cln = try Socket.connect(to: "localhost", port: 9999)
^~~~~~
Socket.Socket:326:17: note: found this candidate
public func connect(to host: String, port: Int32) throws
^
Socket.Socket:332:17: note: found this candidate
public func connect(using signature: Socket.Socket.Signature) throws
^
:0: error: build had 1 command failures
error: exit(1): /home/sharil/swift-3.0-RELEASE-ubuntu14.04/usr/bin/swift-build-tool -f /home/sharil/swift_projects/NetProClient/.build/debug.yaml
The text was updated successfully, but these errors were encountered: