1

I am trying to implement a TCP messaging system in my application.

Here is my code.

In this i am able to send message to target system by entering system name in bottom most line edit. last but one is for message to send.

When a client receives message a message box will be popped.

Some times its working and some times its not working.

I made this modules to send message to multiple systems by entering systems in systems box separating them with comma (,)

Here The major issue is, i am able to send message only for the first person but not for the remainig.

Can any one help me how can i solve this issue.

Rao
  • 2,902
  • 14
  • 52
  • 70

2 Answers2

1

Got the solution. Updated in pastbin

Need to update the SendData definition

def SendData(self):

    TargetSystems = self.targetSystem.text().split(',')
    Msg2Send = self.lineedit.text()

    for TargetSystem in TargetSystems:

        self.Clientsocket.connectToHost(TargetSystem, PORT)
        self.Clientsocket.waitForConnected(-1)  # This is required data to be writing
        self.request = QtCore.QByteArray()
        stream = QtCore.QDataStream(self.request, QtCore.QIODevice.WriteOnly)
        stream.setVersion(QtCore.QDataStream.Qt_4_2)
        stream.writeUInt32(0)
        stream.writeQString(Msg2Send)
        stream.device().seek(0)
        stream.writeUInt32(self.request.size() - SIZEOF_UINT32)
        self.Clientsocket.write(self.request)
        self.nextBlockSize = 0
        self.request = None
        self.Clientsocket.disconnectFromHost() # .close() is not closing the socket connection, so i changed it this
Rao
  • 2,902
  • 14
  • 52
  • 70
0

Tried some options but nmap never shows that port as open, the best solution was right here listening the conversation.

PyQt QTcpServer: How to return data to multiple clients?

The line when you start the server had something wrong, this is the one that got it right.

self.tcpServer.listen(QtNetwork.QHostAddress("0.0.0.0"), PORT)

The function socketError is being called in every sent message, that's homework I guess.

Always wanted to write my own super secret messaging app in pyqt but I'm such a lazy coder this days (I'm being forced to code PHP O_O), maybe now I will based on yours.

Community
  • 1
  • 1
MGP
  • 2,981
  • 35
  • 34
  • i have checked your link long. This was derived from there itself. But there, there is a single server for which all clients connects and send message to server. Then server will send back the message to all the clients which are connected to it. Here you need a server running some where. But in scenario, On every system a server will be initialized and listening for incoming connections. And client is initialized for sending messages to other severs on the network. Once a message is received at server, it will then emit a PyQt signal there. This signal is connected to display message. – Rao Dec 28 '12 at 04:25
  • For sending message client instance is used. This while sending, it will connect to the destination system server listening port and sends the data and closes the socket connection to that host. Hope you are clear now. what i am trying to do. – Rao Dec 28 '12 at 04:26
  • Yes I get the difference but I could not see the port open, with your changes now it doesn't work for me. Also I can't find it in pastebin. – MGP Dec 28 '12 at 14:55
  • I have updated the pastbin link. check now and let me know if you have any issue. – Rao Jan 02 '13 at 07:23