Skip to main content

Gurux network media is used to commmunication with TCP/IP or UDP connections.

Project description

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. Gurux media components also support the following connection types: serial port.

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 intall package:

pip install gurux-common
pip install gurux-net

Simple example

Before use you must set following settings:

  • HostName
  • Port
  • Protocol

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

  • onError
  • onReceived
  • onMediaStateChange

and if in server mode following events might be important.

  • onClientConnected
  • onClientDisconnected
import time
from gurux_common import ReceiveParameters
from gurux_common import IGXMediaListener
from gurux_common.enums.TraceLevel import TraceLevel
from gurux_net import GXNet
from gurux_net.enums import NetworkType
# ---------------------------------------------------------------------------
# This example sends data to the server and waits reply.
# ---------------------------------------------------------------------------
#pylint: disable=no-self-argument
class sampleclient(IGXMediaListener):

    def __init__(self):
        #Define End Of Packet char.
        eop = '\r'
        #Make connection using TCP/IP to localhost.
        media = GXNet(NetworkType.TCP, "localhost", 0)
        #Start to listen events from the media.
        media.addListener(self)

        #Update port to demonstrate onPropertyChanged event.
        media.port = 1000
        #Show all traces. In default traces are not sent.
        media.trace = TraceLevel.VERBOSE
        #Set EOP for the media.
        media.eop = eop
        try:
            #Open the connection.
            media.open()
            r = ReceiveParameters()
            r.eop = eop
            r.count = 5
            #Wait reply for 2 seconds.
            r.waitTime = 2000
            ############################
            #Send data synchronously.
            with media.getSynchronous():
                media.send("Hello world!")
                #Send EOP
                media.send('\r')
                ret = media.receive(r)
                if ret:
                    print(str(r.reply.decode("ascii")))
                else:
                    raise Exception("Failed to receive reply from the server.")
            ############################
            #Send async data.
            media.send("Server !\r")
            #Wait 1 second to receive reply from the server.
            time.sleep(1)
        except Exception as ex:
            print(ex)
        media.close()
        media.removeListener(self)

    def onError(self, sender, ex):
        """
        Represents the method that will handle the error event of a Gurux
        component.

        sender :  The source of the event.
        ex : An Exception object that contains the event data.
        """
        print("Error has occured. " + str(ex))

    def onReceived(self, sender, e):
        """Media component sends received data through this method.

        sender : The source of the event.
        e : Event arguments.
        """
        print("New data is received. " + str(e))

    def onMediaStateChange(self, sender, e):
        """Media component sends notification, when its state changes.
        sender : The source of the event.
        e : Event arguments.
        """
        print("Media state changed. " + str(e))

    def onTrace(self, sender, e):
        """Called when the Media is sending or receiving data.

        sender : The source of the event.
        e : Event arguments.
        """
        print("trace:" + str(e))

    def onPropertyChanged(self, sender, e):
        """
        Event is raised when a property is changed on a component.

        sender : The source of the event.
        e : Event arguments.
        """
        print("Property {!r} has hanged.".format(str(e)))

if __name__ == '__main__':
    sampleclient()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gurux_net-1.0.9.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gurux_net-1.0.9-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file gurux_net-1.0.9.tar.gz.

File metadata

  • Download URL: gurux_net-1.0.9.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for gurux_net-1.0.9.tar.gz
Algorithm Hash digest
SHA256 46261e341c248aa27a2c20ccf237ce48655a25e7e3b1fa3afb2ccc94e8efc905
MD5 ff0e85e4669b7899206831da2d99cecf
BLAKE2b-256 2cd0109cb7f0a45e3481f4f7737c5d09487898849551eb576a5a75ea425baf9e

See more details on using hashes here.

File details

Details for the file gurux_net-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: gurux_net-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for gurux_net-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4f3193ca6b0cc416063fcee06a92285068a82a10b2d272153317489c0f997c85
MD5 061de0ab770c09af51431435960e1de7
BLAKE2b-256 128bc562d5e0c9f2eb473f36db26a6207402b96e875c272a6442c7f2f2d3a7e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page