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);
		}
	
	}
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-12-31
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-05
  • 2022-12-23
  • 2021-06-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案