-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: server 包 Server 新增 RegMessageReadyEvent 函数
- Loading branch information
1 parent
034ca17
commit 04c40bf
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package client_test | ||
|
||
import ( | ||
"github.com/kercylan98/minotaur/server" | ||
"github.com/kercylan98/minotaur/server/client" | ||
"sync" | ||
"testing" | ||
) | ||
|
||
func TestClient_WriteWS(t *testing.T) { | ||
var wait sync.WaitGroup | ||
wait.Add(1) | ||
srv := server.New(server.NetworkWebsocket) | ||
srv.RegConnectionReceivePacketEvent(func(srv *server.Server, conn *server.Conn, packet []byte) { | ||
srv.Shutdown() | ||
}) | ||
srv.RegStopEvent(func(srv *server.Server) { | ||
wait.Done() | ||
}) | ||
srv.RegMessageReadyEvent(func(srv *server.Server) { | ||
cli := client.NewWebsocket("ws://127.0.0.1:9999") | ||
cli.RegConnectionOpenedEvent(func(conn *client.Client) { | ||
conn.WriteWS(2, []byte("Hello")) | ||
}) | ||
if err := cli.Run(); err != nil { | ||
panic(err) | ||
} | ||
}) | ||
if err := srv.Run(":9999"); err != nil { | ||
panic(err) | ||
} | ||
|
||
wait.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters