我有一個關於GWT的問題。假設我的GWT客戶端應用程序需要連接到TCP套接字,做一些事情並關閉它。現在它幾乎不可能在GWT中作爲套接字在客戶端不起作用。java GWT服務器創建套接字
但實際上我可以創建應用程序的服務器端的插座,這樣的:
package com.kurjerzy.testGWT.server;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.Socket;
import com.kurjerzy.testGWT.client.GreetingService;
import com.kurjerzy.testGWT.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public String greetServer(String input) throws IllegalArgumentException {
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
// Escape data from the client to avoid cross-site script vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
String rStr = null;
try {
InetAddress addr = Inet4Address.getByName("google.com");
Socket s = new Socket(addr , 80);
rStr = "connected!";
} catch (Exception e) {
rStr = "e: " + e.getMessage();
}
return "Hasdasdello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent + "<br>rStr=" + rStr;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&").replaceAll("<", "<")
.replaceAll(">", ">");
}
}
但不幸的是serverlet不必創建套接字連接權限,並引發異常。
任何想法如何實現?
我想實現的事情是:
1)具有天然的Java,Android和GWT具有的所有客戶端提供的邏輯的服務器實時遊戲客戶端連接到服務器
2)一次
所以native-java和android客戶端可能會使用傳統tcp套接字連接到服務器。現在我希望允許連接到HTML5的環境相同的遊戲服務器,但我想不通的連接傳輸我應該用什麼...
可能的礦山思路是:
a)作出serverlet接受RPC調用並使用套接字與遊戲服務器進行通信(但如何通過該權限denited?)
b)使gwt客戶端使用一些第三方javascript套接字庫並直接連接到遊戲服務器(但哪一個很好用?)
也許你有更好的想法?
遊戲是基於所以它不是時間關鍵碼轉,但數據被傳輸實時(延遲是可以接受的,但連接必須保持所有以通知第一玩家移動第二播放器的時間)預先
感謝。