Giter VIP home page Giter VIP logo

Comments (4)

billabt avatar billabt commented on May 17, 2024

Can I see a bit more code? Thanks.

from bluesocket.

shariltumin avatar shariltumin commented on May 17, 2024

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()

from bluesocket.

billabt avatar billabt commented on May 17, 2024

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.

from bluesocket.

billabt avatar billabt commented on May 17, 2024

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

from bluesocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.