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


Java WebSocket.In方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: wsInterface

import play.mvc.WebSocket; //导入方法依赖的package包/类
public static WebSocket<String> wsInterface() {
    return new WebSocket<String>() {
        @Override
        public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) {
            SimpleChat.start(in,out);
        }
    };
}
 
开发者ID:ngohoangyell,项目名称:Simple-Chat-Websocket-Java-PlayFramework,代码行数:9,代码来源:Application.java

示例11: join

import play.mvc.WebSocket; //导入方法依赖的package包/类
/**
 * Join the default room.
 */
public static void join(final String username, WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out)
        throws Exception {

    // Send the Join message to the room
    String result = (String) Await.result(ask(ROOM, new Join(username, out), 1000), Duration.create(1, SECONDS));

    if ("OK".equals(result)) {

        // For each event received on the socket,
        in.onMessage(new Callback<JsonNode>() {
            public void invoke(JsonNode event) {

                // Send a Talk message to the room.
                ROOM.tell(new Talk(username, event.get("text").asText()), null);

            }
        });

        // When the socket is closed.
        in.onClose(new Callback0() {
            public void invoke() {

                // Send a Quit message to the room.
                ROOM.tell(new Quit(username), null);

            }
        });
    } else {
        // Cannot connect, create a Json error.
        ObjectNode error = Json.newObject();
        error.put("error", result);

        // Send the error to the socket.
        out.write(error);
    }
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:40,代码来源:MessageRoom.java

示例12: openEditorSocket

import play.mvc.WebSocket; //导入方法依赖的package包/类
public static WebSocket<String> openEditorSocket(String pID) {
    ActorRef workspaceActor = Global.services.createEditor("10", "4");
    ActorRef webSocketActor = Akka.system().actorOf(Props.create(ServicesWebSocketActor.class, workspaceActor));

    return new WebSocket<String>() {
        public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) {
            webSocketActor.tell(new ServicesWebSocketActor.Init(in, out), ActorRef.noSender());
        }
    };
}
 
开发者ID:chrrasmussen,项目名称:NTNU-Master-Project,代码行数:11,代码来源:AssignmentController.java

示例13: ws

import play.mvc.WebSocket; //导入方法依赖的package包/类
public static WebSocket<String> ws() {
    final Request request = request();
    return new WebSocket<String>() {
        @Override
        public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) {
            wsTransportServer.on(new PlayServerWebSocket(request, in, out));
        }
    };
}
 
开发者ID:vibe-project,项目名称:vibe-examples,代码行数:10,代码来源:Bootstrap.java

示例14: onReady

import play.mvc.WebSocket; //导入方法依赖的package包/类
@Override
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
	try {
		this.out = out;
		// Only write out initial data for new connections, not reconnections
		if (!reconnect) {
			writeInitialData(out);
		}
		in.onMessage(new NationStatesCallback(this));
		access.getWebsocketManager().register(this, in);
	} catch (SQLException e) {
		Logger.error("Exception while setting up websocket", e);
	}
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:15,代码来源:NationStatesWebSocket.java

示例15: join

import play.mvc.WebSocket; //导入方法依赖的package包/类
/**
 * Tritt der Spielhalle bei.
 */
public static void join(final User user, WebSocket.In<JsonNode> in,
		WebSocket.Out<JsonNode> out) throws Exception {

	// Sende eine Join-Nachricht an die Spielhalle
	String result = (String) Await.result(
			ask(defaultHall, new Join(user, out), 1000),
			Duration.create(10, SECONDS));

	// Wenn der Zutritt genehmigt wurde, ...
	if ("OK".equals(result)) {

		// Für jede empfangene Nachricht (Spielfelddaten) ...
		in.onMessage(new Callback<JsonNode>() {
			public void invoke(JsonNode event) throws Throwable {

				ObjectMapper mapper = new ObjectMapper();
				Playground aPlayground = mapper.readValue(event,
						new TypeReference<Playground>() {
						});

				// Sende die Spielfelddaten an die Spielhalle.
				defaultHall.tell(aPlayground);
			}
		});
		
		// Wenn der Websocket geschlossen wird, ...
           in.onClose(new Callback0() {
              public void invoke() {
                  
                  // Sende eine Quit-Nachricht zum Entfernen des Nutzers aus der Map.
                  defaultHall.tell(new Quit(user));
                  
              }
           });
	}
}
 
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:40,代码来源:GameHall.java


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