mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-24 19:42:00 -08:00
Keeps component connection open
This commit is contained in:
parent
b21fee420f
commit
24ac2c0526
@ -128,7 +128,7 @@ func (c *Client) Recv() <-chan interface{} {
|
|||||||
|
|
||||||
// Send sends message text.
|
// Send sends message text.
|
||||||
func (c *Client) Send(packet string) error {
|
func (c *Client) Send(packet string) error {
|
||||||
fmt.Fprintf(c.Session.socketProxy, packet)
|
fmt.Fprintf(c.Session.socketProxy, packet) // TODO handle errors
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fluux.io/xmpp"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"fluux.io/xmpp"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
component := xmpp.Component{Host: "mqtt.localhost", Secret: "mypass"}
|
component := xmpp.Component{Host: "mqtt.localhost", Secret: "mypass"}
|
||||||
component.Connect("localhost:8888")
|
component.Connect("localhost:8888")
|
||||||
|
|
||||||
|
for {
|
||||||
|
_, packet, err := component.ReadPacket()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("Packet received: ", packet)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,12 @@ func (c *Component) Connect(connStr string) error {
|
|||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadPacket reads next incoming XMPP packet
|
||||||
|
// TODO use defined interface Packet
|
||||||
|
func (c *Component) ReadPacket() (xml.Name, interface{}, error) {
|
||||||
|
return next(c.decoder)
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// XMPP packets struct
|
// XMPP packets struct
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
|||||||
// Scan XML token stream for next element and save into val.
|
// Scan XML token stream for next element and save into val.
|
||||||
// If val == nil, allocate new element based on proto map.
|
// If val == nil, allocate new element based on proto map.
|
||||||
// Either way, return val.
|
// Either way, return val.
|
||||||
|
// TODO Use an interface to return packets interface xmppDecoder
|
||||||
func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
||||||
// Read start element to find out what type we want.
|
// Read start element to find out what type we want.
|
||||||
se, err := nextStart(p)
|
se, err := nextStart(p)
|
||||||
|
Loading…
Reference in New Issue
Block a user