2012-10-20 94 views

回答

5

例子:

让我们写一个完全丢弃输入数据,只是发送你好后关闭套接字另一个例子!消息:

public static WebSocket<String> index() { 
    return new WebSocket<String>() { 

     public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) { 
      out.write("Hello!"); 
      out.close() 
     } 
    } 
} 

ScalaWebSockets

def index = WebSocket.using[String] { request => 

    // Just consume and ignore the input 
    val in = Iteratee.consume[String]() 

    // Send a single 'Hello!' message and close 
    val out = Enumerator("Hello!") >>> Enumerator.eof 

    (in, out) 
} 
相关问题