Socket.IO在循环内的emit函数,Java版。

huangapple 未分类评论59阅读模式
英文:

Socket.IO emit function inside Loop Java

问题

尝试在 while 循环内发送

Socket socket = IO.socket("http://18.223.196.164:9000");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
    @Override
    public void call(Object... objects) {
        int i = 0;
        while (camera.read(mat)) {
            byte[] data = new byte[(int) (mat.total() * mat.channels())];
            mat.get(0, 0, data);
            obj.addProperty("data", Base64.getEncoder().encodeToString(data));
            socket.emit("liveFeed", obj);
            logger.info("Inside loop" + (++i) + " ");
        }
    }
});
socket.connect();

通过 while 循环连续发送帧但显然服务器只收到一个第一个
英文:

Trying to emit inside while loop

Socket socket = IO.socket("http://18.223.196.164:9000");
	socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
		@Override
		public void call(Object... objects) {
			int i=0;
			while (camera.read(mat)) {
				byte[] data = new byte[(int) (mat.total() * mat.channels())];
				mat.get(0, 0, data);
				obj.addProperty("data", Base64.getEncoder().encodeToString(data));
				socket.emit("liveFeed",obj);
				logger.info("Inside loop"+(++i)+" ");
			}
		}
	});
	socket.connect();

Sending frames continuously through while loop But apparently server receives only one(First) frame.

huangapple
  • 本文由 发表于 2020年5月5日 16:20:52
  • 转载请务必保留本文链接:https://java.coder-hub.com/61608751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定