blob: 47b0bb9b58e4d343a82f6fdff893bfcf426a8f3e [file] [log] [blame]
Francisco Souza3b94eae2012-09-06 15:22:57 +10001// 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
5package websocket_test
6
7import (
8 "io"
9 "net/http"
10
11 "code.google.com/p/go.net/websocket"
12)
13
14// Echo the data received on the WebSocket.
15func EchoServer(ws *websocket.Conn) {
16 io.Copy(ws, ws)
17}
18
19// This example demonstrates a trivial echo server.
20func ExampleHandler() {
21 http.Handle("/echo", websocket.Handler(EchoServer))
22 err := http.ListenAndServe(":12345", nil)
23 if err != nil {
24 panic("ListenAndServe: " + err.Error())
25 }
26}