Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt4 import QtCore,QtGui,QtNetwork
- class test(QtGui.QWidget):
- def __init__(self,parent=None):
- QtGui.QWidget.__init__(self,parent)
- self.layout=QtGui.QVBoxLayout(self)
- self.toSent=QtGui.QLineEdit(self)
- self.received=QtGui.QLineEdit(self)
- self.button=QtGui.QPushButton('SEND')
- self.layout.addWidget(self.toSent)
- self.layout.addWidget(self.received)
- self.layout.addWidget(self.button)
- self.soc=QtNetwork.QTcpSocket(self)
- self.button.clicked.connect(self.connecting)
- self.soc.connected.connect(self.sending)
- self.soc.bytesWritten.connect(self.reading)
- self.show()
- def connecting(self):
- self.soc.connectToHost('192.168.1.74',23000)
- def sending(self):
- payload=self.toSent.text()
- payload.append(chr(13))
- print self.soc.writeData(payload)
- def reading(self):
- a=str(self.soc.readAll())
- print 'READ:',a
- self.received.setText(a)
- self.soc.disconnectFromHost()
- app=QtGui.QApplication(sys.argv)
- ins=test()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement