gurux网络媒体用于与tcp/ip或udp连接进行通信。

gurux-net的Python项目详细描述


有关概述,请参见Gurux

加入gurux社区或按照@Gurux进行项目更新。

使用gurux.net组件,您可以使用tcp或udp连接轻松地同步或异步发送数据。

开源gxnet媒体组件,由gurux有限公司制造,是gxmedias媒体组件集的一部分,它的编程接口帮助您通过选择的连接类型实现通信。gurux媒体组件还支持以下连接类型:串行端口。

更多信息请查看Gurux

我们正在更新gurux网页上的文档。

如果你有问题,可以在guruxForum中提问。

您可以从http://www.github.com/gurux或intall包中获取源代码:

pipinstallgurux-commonpipinstallgurux-net

简单示例

使用前必须设置以下设置:

  • 主机名
  • 端口
  • 协议

还可以添加侦听器来侦听以下事件。

  • 错误
  • 收到时
  • onmediastatechange

如果在服务器模式下,以下事件可能很重要。

  • onclientconnected
  • onclientdisconnected
importtimefromgurux_commonimportReceiveParametersfromgurux_commonimportIGXMediaListenerfromgurux_common.enums.TraceLevelimportTraceLevelfromgurux_netimportGXNetfromgurux_net.enumsimportNetworkType# ---------------------------------------------------------------------------# This example sends data to the server and waits reply.# ---------------------------------------------------------------------------#pylint: disable=no-self-argumentclasssampleclient(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=eoptry:#Open the connection.media.open()r=ReceiveParameters()r.eop=eopr.count=5#Wait reply for 2 seconds.r.waitTime=2000#############################Send data synchronously.withmedia.getSynchronous():media.send("Hello world!")#Send EOPmedia.send('\r')ret=media.receive(r)ifret:print(str(r.reply.decode("ascii")))else:raiseException("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)exceptExceptionasex:print(ex)media.close()media.removeListener(self)defonError(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))defonReceived(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))defonMediaStateChange(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))defonTrace(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))defonPropertyChanged(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()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在Eclipse中使用ctrlshiftt而不是ctrlshiftr有什么好处?   java自动装箱概念SCJP   java如何使用JAXR和Resteasy、Angular和Wildfly10处理COR   java如何在整数数组中动态添加元素?   JAVA从继承生成器模式返回父对象继承   java问题调试生产者消费者问题   java MQ:已达到通道的最大实例数   JavaPowerMockMockito:我试图stubb的方法最终被调用   java Hibernate将多个列映射到一个表   在java中,将字符串中的单词大写,但跳过字符串中的数字和多余空格或符号   使用Eclipse将Java项目导出到JAR时出现“重复条目”错误   java使用eclipselink在实体表上指定NullConstraint   <Java>我可以在TCPIP中使用多个服务器socket吗?   带有自定义视图的java AlertDialog:调整大小以包装视图的内容   如何从用C#编写的web服务生成用于java的SOAP API?