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