[英]SocketIO Client in Java, how to implement working with netty-socketio Server?
[英]How to configure the netty-SocketIO server so that it is accessible from all remote java clients in jelastic
我正在開發一個 Spring-Boot 項目,其中還包括一個基於 netty-socket Io 的 socketIO 服務器。 因此有兩個客戶端:一個 web 客戶端和一個 android 客戶端,它們都在本地工作得很好。 但是當我在 Jelastic 中部署在線服務器時,只有 web 客戶端訪問 netty-SocketIO 服務器,但 android 客戶端無法連接到 netty-SocketIO 服務器。 有人可以幫我配置 netty-socketIO 服務器以接受來自端口 8888 上任何地址的所有請求
服務器配置
Configuration config = new Configuration();
//config.setHostname("sec.j.layershift.co.uk");
config.setHostname("0.0.0.0");
config.setPort(8888);
final SocketIOServer server = new SocketIOServer(config);
// Listen for client connections
server.addConnectListener(client -> {
System.out.println("************ Client: " + getIpByClient(client) + " Connected ************");
});
Web客戶端配置
@CrossOrigin("*")
@RestController
public class ClientLocation {
Socket socket =null;
EventBuilder eventBuilder =null;
Gson gs = new Gson();
//................................
socket = IO.socket("http://sec.j.layershift.co.uk:8888");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
ChatObject co = new ChatObject("ADMIN", "");
String infUser = gs.toJson(co);
System.out.println("\n"+infUser);
JSONObject jb = new JSONObject();
try {
// jb.put("userName", co.getUserName());
// jb.put("message", co.getMessage());
jb = new JSONObject(infUser);
socket.emit("username", jb);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java或android客戶端的配置
private void clientIO(){
try {
socket = IO.socket("http://aug-sec.j.layershift.co.uk:8888");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
NB。 the configuration of the java or android client is identical to that of the web because all use the Socket.IO v1.0.0. 但是只有 web 客戶端可以從 Jelastic 主機工作,因為它與服務器位於同一文件夾中,並且 java 客戶端不成功,因此一切都在本地主機或局域網中運行
有2種可能的解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.