Skip to content

Gurux/gxnet-go

Repository files navigation

See An Gurux for an overview.

Join the Gurux Community or follow @Gurux for project updates.

With gurux.net component you can send data easily syncronously or asyncronously using TCP or UDP connection.

Open Source GXNet media component, made by Gurux Ltd, is a part of GXMedias set of media components, which programming interfaces help you implement communication by chosen connection type. For more info check out Gurux.

We are updating documentation on Gurux web page.

If you have problems you can ask your questions in Gurux Forum.

You can get source codes from http://www.github.com/gurux or add reference to your project:

go get github.com/Gurux/gxcommon-go@v1.0.1
go get github.com/Gurux/gxnet-go@v1.0.1

Simple example

Before use you must set following settings:

  • HostName
  • Port
  • Protocol

It is also good to add listener to listen following events.

  • SetOnError
  • SetOnReceived
  • SetOnMediaStateChange
media := gxnet.NewGXNet(gxnet.TCP, "127.0.0.1", 4059)
media.open()

Data is send with send command:

media.Send("Hello World!", "")

In default mode received data is coming as asynchronously from OnReceived event. Event listener is added like this:

media.SetOnReceived(func(m gxcommon.IGXMedia, e gxcommon.ReceiveEventArgs) {
	fmt.Printf("Async data: %s\n", e.String())
})

Data can be also send as syncronous if needed.

defer media.GetSynchronous()()
err = media.Send("Hello World!\n", "")
if err != nil {
    fmt.Fprintln(os.Stderr, "error:", err)
    return
}
r := gxcommon.NewReceiveParameters[string]()
r.EOP = "\n"
r.WaitTime = *w
r.Count = 0
ret, err := media.Receive(r)
if err != nil {
    fmt.Fprintln(os.Stderr, "error returned:", err)
    return
}
if ret {
    fmt.Printf("Sync data: %s\n", r.Reply)
}

About

Gurux Network component for Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages