Giter Site home page Giter Site logo

Comments (6)

billabt avatar billabt commented on May 18, 2024

The easiest way is to use the isReadableOrWritable function. The basic steps are as follows:

  1. Create the socket.
  2. Set the socket to non-blocking mode using setBlocking(mode: false).
  3. Issue the connect.
  4. Call isReadableOrWritable(waitForever: false, timeout: yourTimeout) function on the socket using your desired timeout.
  5. If the returned tuple indicates that it's writable, you're connected, if not, the timeout has occurred.
  6. Reset the blocking mode back to blocking if desired...

from bluesocket.

SelvaBalasubramanian avatar SelvaBalasubramanian commented on May 18, 2024

I tried but the same problem occurs.The problem what I am facing is when the socket.connect(ip, port) starts executing it waits for some time to connect.

from bluesocket.

SelvaBalasubramanian avatar SelvaBalasubramanian commented on May 18, 2024

here is the code!!
I need to implement a network scan...for availability of a particular ip and port...
`

func searchController(){
    let ipString = "192.168.1."
    let port = 8286
    var k = 1
    
    let socket = try? Socket.create()
    while(k <= 255){

        let ip = ipString + "\(k)"
        try? socket?.setBlocking(mode: false)
        print("function entered")
            try?  socket?.connect(to: ip , port: Int32(port))
           print(k)
        let result = try? socket?.isReadableOrWritable(waitForever: false, timeout: UInt(0
        ))
        
        if result??.writable != nil {
            if result.unsafelyUnwrapped?.writable == true{
                print(ip  + " " + "\(port)" )
            }
            }else{
                socket?.close()
            }else{
                 socket?.close()
             }
     k +=  1

}
    
}`

from bluesocket.

SelvaBalasubramanian avatar SelvaBalasubramanian commented on May 18, 2024

i tried but it still waits in socket?.connect(to: ip , port: Int32(port))

from bluesocket.

mna avatar mna commented on May 18, 2024

I can confirm the same behaviour for me on Darwin, see https://github.com/mna/testconnecttimeout to reproduce. Blocks on the call to socket.connect even though the socket is in non-blocking mode.

from bluesocket.

billabt avatar billabt commented on May 18, 2024

Fixed in 0.12.60.

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.