holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.04k stars 84 forks source link

Why Socket Auto Closed After Send Data #52

Closed xctest closed 4 years ago

xctest commented 4 years ago

everytime when i send data using socket, it always closed after sending, so how to keep the connection.

this is my swarm configuration:

const swarm = hyperswarm({
    ephemeral: false,
})
swarm.join(topic, {
    lookup: true,
     announce: true
})
// i use end to send data
socket.end(someText)

any help is appreciated!

davidmarkclements commented 4 years ago

if you don't want a socket to close, don't use end to send data, use write

https://nodejs.org/api/net.html#net_socket_end_data_encoding_callback https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback