SocketIO Client


package com.x061.socketio.demo;

import org.json.JSONObject;

import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;


public class ClientDemo {
	public static void main(String[] args) throws Exception {
		IO.Options options = new IO.Options();
		options.transports = new String[]{"websocket"};
		options.reconnectionAttempts = 2;
		options.reconnectionDelay = 1000;
		
		final Socket socket = IO.socket("http://localhost:5000/", options);
		
		socket.on("test_response", new Emitter.Listener() {
			
			@Override
			public void call(Object... arg0) {
				JSONObject obj = (JSONObject)arg0[0];
				System.out.println(obj.toString());
			}
		});
		
		socket.connect();
		
		JSONObject sendObj = new JSONObject();
		sendObj.put("msg", "dddd");
		socket.emit("test", sendObj);
		
		while(true){
			Thread.sleep(1000);
		}
	
	}
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM