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

View File

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