Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to connect to make websocket connection. #1

Open
jatin510 opened this issue Jul 8, 2021 · 0 comments
Open

not able to connect to make websocket connection. #1

jatin510 opened this issue Jul 8, 2021 · 0 comments

Comments

@jatin510
Copy link

jatin510 commented Jul 8, 2021

Hi !
I ran the code with yarn start:dev command.

I can connect to the http://localhost:3000.

But when I tried connecting to the ws server. I can't connect to it.

What I tried.

This is my index.html file

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    hello
    <script src="./client.js"></script>
  </body>
</html>


client.js

// establish a connection to the server
const socket = new WebSocket('ws://localhost:3000');
console.log(socket);
socket.onopen = () => {
  // now we are connected
  console.log('connected');
  socket.send('some text'); // send some text to server
};
socket.onmessage = (message) => {
  // here we got something sent from the server
  console.log('closed');
};
socket.onclose = () => {
  console.log('closed');
};

Output: In chrome console

client.js:2 WebSocket connection to 'ws://localhost:3000/' failed: 
closed

@jatin510 jatin510 changed the title not able to connect to make websocket connectin. not able to connect to make websocket connection. Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant