以下代码来自我的Javascipt(用Angualr编写),该代码将加载到Android应用程序的Webview中,谁能建议我们如何创建服务器来监听我的客户端代码
let webSocketURL = "ws://localhost:8080";
webSocket:any;
message = '';
try {
this.webSocket = new WebSocket(webSocketURL);
this.webSocket.onopen = (openEvent)=>{
this.message = "WebSocket OPEN";
this.webSocket.send('hello from client');
};
this.webSocket.onclose = (closeEvent) =>{
this.message = "WebSocket CLOSE";
};
this.webSocket.onerror = (errorEvent) => {
this.message = "WebSocket ERROR";
};
this.webSocket.onmessage = (messageEvent) =>{
this.message = "Got message from server is "+ messageEvent;
console.log('messageEvent',messageEvent);
};
} catch (exception) {
console.error(exception);
this.message = " Got exception" + exception ;
}
在HTML页面中,我将打印“消息”变量
<h2>Here your message {{message}} </h2>