Skip to content

Instantly share code, notes, and snippets.

@davecheney
Created March 10, 2011 23:06
Show Gist options
  • Save davecheney/865147 to your computer and use it in GitHub Desktop.
Save davecheney/865147 to your computer and use it in GitHub Desktop.
package xmpp
import (
"fmt"
"net"
"os"
"crypto/tls"
"xml"
)
type Client struct {
conn net.Conn
Parser *xml.Parser
}
func Dial() (*Client, os.Error) {
conn, err := net.Dial("tcp", "", "talk.google.com:5222")
if err != nil {
return nil, err
}
_, err = fmt.Fprint(conn, "<?xml version='1.0' ?><stream:stream to='cheney.net' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>")
if err != nil {
return nil, err
}
return &Client {
conn: conn,
Parser: xml.NewParser(conn),
}, nil
}
func (c *Client) Starttls() os.Error {
_, err := fmt.Fprint(c.conn, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>")
if err != nil {
return err
}
tlsconn := tls.Client(c.conn, nil)
c.conn = tlsconn
return tlsconn.Handshake()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment