examples/chat: Use new listen/dial API

This commit is contained in:
Sasha Koshka 2025-10-20 17:59:51 -04:00
parent c9480ba016
commit 2e4c693174
2 changed files with 6 additions and 9 deletions

View File

@ -47,13 +47,10 @@ func main() {
func join(address string, room string, nickname string) (hopp.Trans, error) {
ctx, done := context.WithTimeout(context.Background(), 16 * time.Second)
defer done()
dialer := hopp.Dialer {
TLSConfig: &tls.Config {
conn, err := hopp.Dial(ctx, "tls", address, &tls.Config {
// don't actually do this in real life
InsecureSkipVerify: true,
},
}
conn, err := dialer.Dial(ctx, "tcp", address)
})
if err != nil { return nil, err }
transRoom, err := conn.OpenTrans()

View File

@ -28,7 +28,7 @@ func main() {
func host(address string, certPath, keyPath string) error {
keyPair, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil { return err }
listener, err := hopp.ListenTLS("tcp", address, &tls.Config {
listener, err := hopp.Listen("tls", address, &tls.Config {
InsecureSkipVerify: true,
Certificates: []tls.Certificate { keyPair },
})
@ -60,11 +60,11 @@ func (this *client) run() {
for {
log.Println("accepting transaction")
trans, err := this.conn.AcceptTrans()
log.Println("accepted transaction")
if err != nil {
log.Printf("XXX %v failed: %v", this.conn.RemoteAddr(), err)
return
}
log.Println("accepted transaction")
go this.runTrans(trans)
}
}