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

ambiguous reference to member 'connect(to:port:) #19

Closed
shariltumin opened this issue Oct 3, 2016 · 4 comments
Closed

ambiguous reference to member 'connect(to:port:) #19

shariltumin opened this issue Oct 3, 2016 · 4 comments

Comments

@shariltumin
Copy link

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

@billabt
Copy link
Collaborator

billabt commented Oct 3, 2016

Can I see a bit more code? Thanks.

@shariltumin
Copy link
Author

Sorry for the trouble. It was my mistake. For what it worth here are my simple examples:

Server:
// SimpleServer

import Socket

var soc = try Socket.create()
var msg = "I don't know"

try soc.listen(on: 9999)

var srv = try soc.acceptClientConnection()
var data = try srv.readString()

print("(data!)")

try srv.write(from: msg)

srv.close()

Client:

// SimpleClient

import Socket

var cln = try Socket.create()

let host = "localhost"
let port: Int32 = 9999
var msg = "Hello, what is the time?"

//let sig = try Socket.Signature(socketType: .stream, proto: .tcp, hostname: host, port: port)
//var cln = try Socket.connectTo(using: sig!)

try cln.connect(to: host, port: port)

try cln.write(from: msg)

var data = try cln.readString()

print("(data!)")

cln.close()

@billabt
Copy link
Collaborator

billabt commented Oct 3, 2016

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.

@billabt
Copy link
Collaborator

billabt commented Oct 3, 2016

No problem... Glad you found it. Let me know if you have anymore questions. In the meantime, I'm going to close this issue.

@billabt billabt closed this as completed Oct 3, 2016
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

2 participants