将我的应用程序部署到亚马逊后,通过websocket的前端和服务器之间的连接不起作用。更准确地说,当我从amazon链接打开前端并在计算机上运行服务器时,它可以工作,但是当其他人尝试通过其他ip使用该应用程序时,消息不会到达服务器。
下面,我放置了建立连接的代码片段。 这是我如何连接到前端(角度)服务器的方法:
public openWebSocket(port : number){
this.webSocket = new WebSocket('ws://192.168.0.16:' + port.toString());
this.webSocket.onopen = (event) => {
//console.log('Open: ', event);
}
this.webSocket.onmessage = (event) => {
//console.log('Received message: ', event);
const msg : Message = JSON.parse(event.data);
switch(msg.Type){ ...
这是我在服务器(C#控制台应用程序)上建立Websocket的方式:
public Server(int port)
{
//setup websocket
_port = port;
_webSocket = new WebSocketServer();
RootConfig r = new RootConfig();
ServerConfig s = new ServerConfig();
s.Name = "SuperWebSocket";
s.Ip = "Any";
s.Port = port;
s.Mode = SocketMode.Tcp;
SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();
_webSocket.Setup(r, s, f);
_webSocket.Listeners[0].EndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.16"),port);
_webSocket.NewSessionConnected += Connect;
_webSocket.NewDataReceived += DataReceived;
_webSocket.NewMessageReceived += MessageReceived;
_webSocket.SessionClosed += SessionClosed; ...