当前位置: 首页>>代码示例>>Java>>正文


Java WebSocket类代码示例

本文整理汇总了Java中play.mvc.WebSocket的典型用法代码示例。如果您正苦于以下问题:Java WebSocket类的具体用法?Java WebSocket怎么用?Java WebSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocket类属于play.mvc包,在下文中一共展示了WebSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendHistoryMessage

import play.mvc.WebSocket; //导入依赖的package包/类
private void sendHistoryMessage(WebSocket.Out<JsonNode> channel, History history) {
    if (m_members.values().size() > SIZE_THRESHOLD) {
        return;
    }
    
    ObjectNode event = Json.newObject();
    event.put("kind", "history");
    event.put("user", history.talk.username);
    event.put("message", history.talk.text);
    event.put("userId", history.talk.userId);
    event.put("toUser", history.talk.toUserName);
    event.put("toUserId", history.talk.toUserId);
    event.put("isOnline", history.talk.isOnline);
    event.put("isOwners", history.talk.isOwners);
    event.put("peopleNum", m_members.keySet().size());
    event.put("time", sdf.format(history.date));
    
    channel.write(event);
}
 
开发者ID:chengxp3,项目名称:galaxy,代码行数:20,代码来源:RaceChatModel.java

示例2: videoSocket

import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> videoSocket(long id) {
    String[] tokens = request().queryString().get("authToken");

    if (tokens == null || tokens.length != 1 || tokens[0] == null)
        return WebSocket.reject(unauthorized());

    Drone drone = Drone.FIND.byId(id);
    if (drone == null)
        return WebSocket.reject(notFound(Json.toJson("no drone found with this id")));

    User u = models.User.findByAuthToken(tokens[0]);
    if (u != null) {
        return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
    } else {
        return WebSocket.reject(unauthorized());
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:18,代码来源:DroneController.java

示例3: videoSocket

import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> videoSocket(long id) {
    /*String[] tokens = request().queryString().get("authToken");

    if (tokens == null || tokens.length != 1 || tokens[0] == null)
        return WebSocket.reject(unauthorized());

    User u = models.User.findByAuthToken(tokens[0]);
    if (u != null) {
        return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
    } else {
        return WebSocket.reject(unauthorized());
    }*/
    Drone drone = Drone.FIND.byId(id);
    DroneCommander d = Fleet.getFleet().getCommanderForDrone(drone);
    d.initVideo();

    return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:19,代码来源:Application.java

示例4: Server

import play.mvc.WebSocket; //导入依赖的package包/类
private Server(ActorRef messageRoom) {

        // Create a Fake socket out for the robot that log events to the console.
        WebSocket.Out<JsonNode> serverChannel = new WebSocket.Out<JsonNode>() {

            public void write(JsonNode frame) {
                Logger.info(Json.stringify(frame));
            }

            public void close() {
            }
        };

        // Join the room
        messageRoom.tell(new MessageRoom.Join("Server", serverChannel), null);
    }
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:17,代码来源:Server.java

示例5: connect

import play.mvc.WebSocket; //导入依赖的package包/类
/**
 * Action non standard dédiée aux WebSockets
 */
public static WebSocket<JsonNode> connect() {
    // On peut récupérer des objets de session ici si besoin!
    return new WebSocket<JsonNode>() {
        // Appelé quand le "Handshake" est réalisé lors de la première requête HTTP.
        public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {

            // Joindre la pièce dédiée aux messages.
            try {
                MessageRoom.join(UUID.randomUUID().toString(), in, out);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:19,代码来源:Socket.java

示例6: connect

import play.mvc.WebSocket; //导入依赖的package包/类
/**
 * Action non standard dédiée aux WebSockets
 */
public static WebSocket<JsonNode> connect() {
    // On peut récupérer des objets de session ici si besoin!
    return new WebSocket<JsonNode>() {
        // Appelé quand le "Handshake" est réalisé lors de la première requête HTTP.
        public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {

            // Joindre la pièce dédiée aux messages.
            try {
                MessageRoom.join(UUID.randomUUID().toString(), in, out);
            } catch (Exception ex) {
                Logger.error("Error in WebSocket onReady", ex);
            }
        }
    };
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:19,代码来源:Socket.java

示例7: invokeActor

import play.mvc.WebSocket; //导入依赖的package包/类
/**
 * Invokes a new ActorRef instance of type WebSocketActor for an account ID.
 *
 * @param account Account
 * @param in WebSocket input stream
 * @param out WebSocket output stream
 */
public void invokeActor(final Account account, WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
    if (this.getActorForAccount(account) != null) {
        return;
    }

    this.accountActor.put(account.id, Akka.system().actorOf(Props.create(WebSocketActor.class, account, in, out)));
}
 
开发者ID:socia-platform,项目名称:htwplus,代码行数:15,代码来源:WebSocketService.java

示例8: sendCompleteImage

import play.mvc.WebSocket; //导入依赖的package包/类
private void sendCompleteImage(WebSocket.Out<JsonNode> viewer) {
	
	for (int x = 0; x < imageStrings.length; x++) {
		for (int y = 0; y < imageStrings[x].length; y++) {
			if (imageStrings[x][y] != null) {
				ObjectNode event = Json.newObject();
				event.put("kind", "sendImage");
				event.put("x", x);
				event.put("y", y);
				event.put("data", imageStrings[x][y]);
				viewer.write(event);
			}
		}
	}
	
}
 
开发者ID:JohannBo,项目名称:Hermodr-Server,代码行数:17,代码来源:Session.java

示例9: presenter

import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<JsonNode> presenter(final String presenterName) {
	Logger.info("Application.presenter()");
    return new WebSocket<JsonNode>() {
        
        // Called when the Websocket Handshake is done.
        public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){
            
            // Join the chat room.
            try { 
                Session.createSession(presenterName, in, out);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
}
 
开发者ID:JohannBo,项目名称:Hermodr-Server,代码行数:17,代码来源:Application.java

示例10: viewer

import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<JsonNode> viewer(final String presenterName, final String username) {
	Logger.info("Application.viewer()");
	return new WebSocket<JsonNode>() {
		
		// Called when the Websocket Handshake is done.
		public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){
			
			// Join the chat room.
			try { 
				Session.joinSession(presenterName, username, in, out);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	};
}
 
开发者ID:JohannBo,项目名称:Hermodr-Server,代码行数:17,代码来源:Application.java

示例11: register

import play.mvc.WebSocket; //导入依赖的package包/类
protected void register(NationStatesWebSocket socket, WebSocket.In<JsonNode> in) {
	Set<NationStatesWebSocket> set = pages.get(socket.getPageType());
	synchronized(set) {
		set.add(socket);
		in.onClose(new UnregisterCallback(socket));
	}
	
	count++;
	if (count % 25 == 0) {
		int total = 0;
		for (PageType page : PageType.values()) {
			Set<NationStatesWebSocket> sockets = pages.get(page);
			synchronized(sockets) {
				total += sockets.size();
			}
		}
		Logger.info("Currently " + total + " registered websockets");
	}
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:20,代码来源:WebsocketManager.java

示例12: wsCall

import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> wsCall() {
    return new WebSocket<String>() {
        @SuppressWarnings("unchecked")
        public void onReady(final WebSocket.In<String> in,
                            final WebSocket.Out<String> out) {

            if (Cache.get("channels") == null) {
                List<Out> outs = new ArrayList<Out>();
                outs.add(out);
                Cache.set("channels", outs);
            } else ((List<Out>) Cache.get("channels")).add(out);
            System.out.println("<" + Cache.get("channels"));
            in.onClose(new F.Callback0() {
                @Override
                public void invoke() throws Throwable {
                    ((List<Out>) Cache.get("channels")).remove(out);
                    out.close();
                }
            });
        }
    };
}
 
开发者ID:dhinojosa,项目名称:play-workshop,代码行数:23,代码来源:FitnessController.java

示例13: initializeGame

import play.mvc.WebSocket; //导入依赖的package包/类
private static void initializeGame(ActionRequest actionRequest) {

		final Game game = findGame((Long) actionRequest.data[0]);
		// change game state
		game.superState = Game.STATE_READY;
		game.subState = 0;
		// set active counter to first position in the list of counters
		game.activeCounter = 0;

		// construct the action response
		ActionResponse response = new ActionResponse();
		// define socket request initializing action
		response.initializer = Action.TYPE_INITIALIZE_GAME;
		// assemble socket response data
		response = assembleInitializeGameResponseData(game, response);

		@SuppressWarnings("unchecked")
		WebSocket.Out<JsonNode> out = (WebSocket.Out<JsonNode>) actionRequest.data[1];

		// finally write action response on the socket's out channel
		writeOut(response, out);

		// persist the game state
		game.save();
	}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:26,代码来源:SinglePlayerGameHall.java

示例14: initializeSinglePlayerGame

import play.mvc.WebSocket; //导入依赖的package包/类
/**
 * Controller Action for initiating the web socket.
 */
public static WebSocket<JsonNode> initializeSinglePlayerGame(final Long game) {

	final Session session = session();
	
	return new WebSocket<JsonNode>() {

		public void onReady(WebSocket.In<JsonNode> in,
				WebSocket.Out<JsonNode> out) {
			try {
				SinglePlayerGameHall.join(game,
						UserService.getAuthUserName(session), in, out);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	};
}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:21,代码来源:GameController.java

示例15: administratePlayground

import play.mvc.WebSocket; //导入依赖的package包/类
/**
 * Websocket für das Administrieren der Spielfelder verwalten.
 */
public static WebSocket<JsonNode> administratePlayground() {
	
	final User user = getUMS().getLoggedUser(session());
	
	return new WebSocket<JsonNode>() {
           
           public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){                
               try { 
                   GameHall.join(user, in, out);
               } catch (Exception ex) {
                   ex.printStackTrace();
               }
           }
       };		
}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:19,代码来源:Playgrounds.java


注:本文中的play.mvc.WebSocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。