2
我試圖運行websocket示例。Glassfish服務器在啓動時顯示錯誤
我的客戶端代碼是這個
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Web Socket Implementation</title>
</head>
<body>
<form>
<input id="textmessage" type="text">
<input onclick="sendmessage();" value="Send Message" type="button">
</form>
<br><textarea id="messageTextArea" rows="10" cols="50"></textarea>
<script type="text/javascript">
var webSocket=new
WebSocket("ws://localhost:8080/SimpleWebSocketProj1/serverendpoindemo");
var messageTextArea=document.getElementById("messageTextArea");
webSocket.onopen=function(message){processOpen(message);};
webSocket.onmessage=function(message){processMessage(message);};
webSocket.onclose=function(message){processClose(message);};
webSocket.onerror=function(message){processError(message);};
function processOpen(message)
{
messageTextArea.value +="Server Connect.." + "\n";
}
function onmessage(message)
{
messageTextArea.value +="Receive from server..-->" + message.data
+"\n";
}
function sendmessage()
{ if(textmessage.vaue!="close")
{
webSocket.send(tesxtmessage.value);
messageTextArea.value +="Send to server..-->" +
textmessage.value +"\n";
tesxtmessage.value="";
}
else
webSocket.close();
}
function processClose(message)
{
webSocket.send("Client disconnceted..");
messageTextArea.value +="Server Disconnect.." + "\n";
}
function processError(message)
{
messageTextArea.value +="Error while Connect..\n";
}
</script>
</body>
</html>
這是我的服務器的Java代碼
package com.ws.test;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/serverendpoindemo")
public class ServerEndpoinDemo
{ @OnOpen
public void handleOpen()
{
System.out.println("client is now connected..");
}
@OnMessage
public String handleMessage(String message)
{
System.out.println("receive from client.." +message);
String replymessage="echo " +message;
System.out.println("send to client.." +replymessage);
return replymessage;
}
@OnClose
public void handleClose()
{
System.out.println("client is now disconnected..");
}
@OnError
public void handleError(Throwable t)
{
t.printStackTrace();
}
}
當我試圖在服務器上運行它顯示這樣 Eclipse插件錯誤無法溝通與GlassFish服務器,狀態是:CREDENTIAL_ERROR
@ user3241867:我已經做了它仍然我不能運行,我也嘗試在Eclipse靛藍和朱諾IDE,但尚未解決。 – noviceCodder