Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1695216

Browse files
committed
Add ping example
Closes#227
1 parentde8e29b commit1695216

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

‎autobahn_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ var autobahnCases = []string{"*"}
3636
funcTestAutobahn(t*testing.T) {
3737
t.Parallel()
3838

39-
ifos.Getenv("AUTOBAHN_TEST")=="" {
39+
ifos.Getenv("AUTOBAHN")=="" {
4040
t.SkipNow()
4141
}
4242

43-
ifos.Getenv("AUTOBAHN_FAST")!="" {
43+
ifos.Getenv("AUTOBAHN")=="fast" {
44+
// These are the slow tests.
4445
excludedAutobahnCases=append(excludedAutobahnCases,
4546
"9.*","13.*","12.*",
4647
)

‎example_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ func Example_crossOrigin() {
135135
log.Fatal(err)
136136
}
137137

138+
funcExampleConn_Ping() {
139+
// Dials a server and pings it 5 times.
140+
141+
ctx,cancel:=context.WithTimeout(context.Background(),time.Minute)
142+
defercancel()
143+
144+
c,_,err:=websocket.Dial(ctx,"ws://localhost:8080",nil)
145+
iferr!=nil {
146+
log.Fatal(err)
147+
}
148+
deferc.Close(websocket.StatusInternalError,"the sky is falling")
149+
150+
// Required to read the Pongs from the server.
151+
ctx=c.CloseRead(ctx)
152+
153+
fori:=0;i<5;i++ {
154+
err=c.Ping(ctx)
155+
iferr!=nil {
156+
log.Fatal(err)
157+
}
158+
}
159+
160+
c.Close(websocket.StatusNormalClosure,"")
161+
}
162+
138163
// This example demonstrates how to create a WebSocket server
139164
// that gracefully exits when sent a signal.
140165
//

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp