2012-10-20 135 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) 
} 
相關問題