Comments (6)
The easiest way is to use the isReadableOrWritable function. The basic steps are as follows:
- Create the socket.
- Set the socket to non-blocking mode using setBlocking(mode: false).
- Issue the connect.
- Call isReadableOrWritable(waitForever: false, timeout: yourTimeout) function on the socket using your desired timeout.
- If the returned tuple indicates that it's writable, you're connected, if not, the timeout has occurred.
- Reset the blocking mode back to blocking if desired...
from bluesocket.
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.
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.
i tried but it still waits in socket?.connect(to: ip , port: Int32(port))
from bluesocket.
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.
Fixed in 0.12.60.
from bluesocket.
Related Issues (20)
- Socket listen failed on iOS 14.0.1 HOT 7
- Is it possible observe connection with client? HOT 1
- Error code: -9980(0x-26FC), No route to host HOT 12
- 'listen' function unable to bind address HOT 2
- Download multiple files HOT 2
- Swift bluesocket Can't get long data ? HOT 18
- Warnings in Xcode 13 HOT 10
- Cannot connect to listening UNIX socket HOT 6
- Error code: -9993(0x-2709), Invalid argument HOT 6
- Get local IP address HOT 1
- Echoserver and JavaScript HOT 3
- Can not receive tcp packets in hotspot HOT 1
- Tcp Incomplete receiving data HOT 1
- Unable to detect closed socket HOT 3
- Incompatible with swift-argument-parser v1.0.0+ HOT 9
- is there any other
- Reading Less than SOCKET_MINIMUM_READ_BUFFER_SIZE? HOT 1
- A shell task failed with exit code 72 HOT 1
- Task failed with exit code 70
- Postman can not connect to the Example EchoServer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluesocket.