Comments (6)
I think the "Socket.create" line may not be needed in your attach()
call? It's certainly overriding your socket.listen()
.
from bluesocket.
🤔 indeed must copied here by mistake.
as a workaround I opt out to nc
let pipe = Pipe()
let echo = Process()
echo.launchPath = "/usr/bin/env"
echo.arguments = ["echo"] + args.components(separatedBy: " ")
echo.standardOutput = pipe
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = ["nc", "-U", socketPath]
task.standardInput = pipe
echo.launch()
task.launch()
task.waitUntilExit()
if task.terminationStatus != 0 {
throw Error.processFailed(args)
}
My attach function is now
func attach() async {
do {
let socket = try Socket.create(family: .unix, type: .stream, proto: .unix)
try socket.listen(on: socketPath)
log.info("Listening on \(socketPath)")
while true {
let conn = try socket.acceptClientConnection()
let msg = try conn.readString()?.trimmingCharacters(in: .whitespacesAndNewlines)
conn.close()
await processMessage(msg)
if stop || restart {
log.info("No longer accepting connection to \(socketPath)")
break
}
}
} catch {
log.error("Socket error: \(error)")
}
if restart {
restart = false
await attach()
}
}
from bluesocket.
I had same error but in different context.
do {
let socket = try Socket.create(family: .inet, type: .datagram, proto: .udp)
let destination = Socket.createAddress(for: "localhost", on: 50000)
_ = try socket.write(from: Data("Message".utf8), to: destination!)
print("Sent message to 50000")
} catch {
print("Failed to send message to 50000 - \(error)")
}
It worked few days ago, but now its not and that makes me crazy... the problem in localhost
...if I change it to 127.0.0.1
it start working again. But Im pretty sure it worked with localhost
before. Any ideas why it stop working?
from bluesocket.
If you're on macOS, I think localhost is defined for both ipv4 and ipv6, which I think can sometimes cause confusion. Is it more reliable if you use 127.0.0.1? Also how is your listening side declared?
from bluesocket.
@dannys42 yes, im on macOS. no listener in this example. it just works w/o error if I change to 127.0.0.1
. But I'm very curious about the reason why localhost
stopped working (because it worked few days ago and I have not change source code). So it more likely the issue with my host machine.
/etc/hosts
does have 127.0.0.1 localhost
and ping localhost
in terminal works...
from bluesocket.
/etc/hosts
also has ::1 localhost
. After I removed it - socket start working again. So yes, it were related to ipv4/ipv6. Not sure why it were recognised as AF_INET before and now as AF_INET6, but yes - it will be more reliable to use 127.0.0.1
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
- 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.