stream.go 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package goSam
  2. import (
  3. "fmt"
  4. )
  5. // StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client
  6. func (c *Client) StreamConnect(id int32, dest string) error {
  7. r, err := c.sendCmd("STREAM CONNECT ID=%d DESTINATION=%s\n", id, dest)
  8. if err != nil {
  9. return err
  10. }
  11. // TODO: move check into sendCmd()
  12. if r.Topic != "STREAM" || r.Type != "STATUS" {
  13. return fmt.Errorf("Unknown Reply: %+v\n", r)
  14. }
  15. result := r.Pairs["RESULT"]
  16. if result != "OK" {
  17. return ReplyError{result, r}
  18. }
  19. return nil
  20. }
  21. // StreamAccept asks SAM to accept a TCP-Like connection
  22. func (c *Client) StreamAccept(id int32) (*Reply, error) {
  23. r, err := c.sendCmd("STREAM ACCEPT ID=%d SILENT=false\n", id)
  24. if err != nil {
  25. return nil, err
  26. }
  27. // TODO: move check into sendCmd()
  28. if r.Topic != "STREAM" || r.Type != "STATUS" {
  29. return nil, fmt.Errorf("Unknown Reply: %+v\n", r)
  30. }
  31. result := r.Pairs["RESULT"]
  32. if result != "OK" {
  33. return nil, ReplyError{result, r}
  34. }
  35. return r, nil
  36. }