You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a simple TCP server and client just to try the new API but client refuses(ECONNREFUSED) to connect when I set hostname as localhost in the server. Sharing the code that I am running:
server.ts
Bun.listen<SocketData>({hostname: "localhost",port: 4000,socket: {data(socket,data){console.log("Ack: ",socket.data.sessionId);console.log("Client says: ",data.toString());},// message received from clientopen(socket){console.log("Client connected");socket.data={sessionId: randomUUID(),};socket.write(socket.data.sessionId);},// socket openedclose(socket){console.log("Client disconnected");},// socket closed},});
client.ts
Bun.connect({hostname: "localhost",port: 4000,socket: {data(socket,data){console.log("Got data from server: ",data.toString());},},});
Output:
But as soon as I set the hostname as 127.0.0.1 on the server side it starts to work fine and socket connection/data exchange is getting made.
What is the expected behavior?
Socket connection should be made irrespective of the hostname is set localhost or 127.0.0.1
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered:
PranjalAgni
changed the title
Bun TCP Sockets refuse to connect with "localhost"
Bun TCP Sockets refuse to connect with hostname as "localhost"
Nov 16, 2023
What version of Bun is running?
1.0.11+f7f6233ea
What platform is your computer?
Darwin 23.1.0 x86_64 i386
What steps can reproduce the bug?
I wrote a simple TCP server and client just to try the new API but client refuses(ECONNREFUSED) to connect when I set hostname as
localhost
in the server. Sharing the code that I am running:server.ts
client.ts
Output:
But as soon as I set the hostname as
127.0.0.1
on the server side it starts to work fine and socket connection/data exchange is getting made.What is the expected behavior?
Socket connection should be made irrespective of the hostname is set
localhost
or127.0.0.1
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: