You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
583 B

  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package websocket_test
  5. import (
  6. "io"
  7. "net/http"
  8. "golang.org/x/net/websocket"
  9. )
  10. // Echo the data received on the WebSocket.
  11. func EchoServer(ws *websocket.Conn) {
  12. io.Copy(ws, ws)
  13. }
  14. // This example demonstrates a trivial echo server.
  15. func ExampleHandler() {
  16. http.Handle("/echo", websocket.Handler(EchoServer))
  17. err := http.ListenAndServe(":12345", nil)
  18. if err != nil {
  19. panic("ListenAndServe: " + err.Error())
  20. }
  21. }