简体   繁体   中英

Can not connect to server with socket.io

The socket.io server is running at an aws cloud server. The client and server can be connected on local network. No error is thrown. The client just can not find the node to connect. 在此处输入图像描述

The code of server is:

import Utils from "./utils.js";
import fileUtils from "./fileUtils.js"
import {User} from "./user.js";
import { Server } from "socket.io";
import { createServer } from "https";
import fs from "fs";
import utils from "./utils.js";

// this is a sender(server)
const port= 3000
const io =new Server(port)
const stationType="sender"
let receiver1=new User()



io.on("connection",(socket) => {
...

And the code of client is:

import utils from "./utils.js"
import { io } from "socket.io-client"
import fs from "fs";
import {User} from "./user.js";
import {Server} from "socket.io";

const port =3000 //3000 for sender,3001 for relay
const socket=io("xx.xxx.xx.xxx:"+port) //I hide the IP of the server
const stationType="receiver"
...

I input the ip address of server correctly on client and open the port of 3000 in aws.

Just add "ws://" before IP address on client.

import utils from "./utils.js"
import { io } from "socket.io-client"
import fs from "fs";
import {User} from "./user.js";
import {Server} from "socket.io";

const port =3000 //3000 for sender,3001 for relay
const socket=io("ws://xx.xxx.xx.xxx:"+port) //I hide the IP of the server
const stationType="receiver"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM