Improved network communication
This commit is contained in:
client
server
stresstest
tools/server
32
server/main.go
Normal file
32
server/main.go
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"server/core"
|
||||
"server/game"
|
||||
"server/packet"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Init server
|
||||
server := core.New()
|
||||
server.SetHandler(packet.Ping, game.Ping)
|
||||
server.SetHandler(packet.Login, game.Login)
|
||||
|
||||
// Show statistics
|
||||
last := time.Now()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
if time.Now().After(last.Add(time.Second)) {
|
||||
fmt.Printf("%d packets per second, %d clients\n", server.PacketCount(), game.Clients.Count())
|
||||
last = time.Now()
|
||||
server.ResetPacketCount()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Start listening
|
||||
server.Run(4242)
|
||||
}
|
Reference in New Issue
Block a user