Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:14:30+00:00 2026-05-27T10:14:30+00:00

My application written in PyQt4 doesn’t seem to get any data. readyRead event isn’t

  • 0

My application written in PyQt4 doesn’t seem to get any data.
readyRead event isn’t even fired.
Use of the applications is following:

python server.py -s -p 50000 #(server on port 50000)
python server.py -c -p 50000 #(client sending data to port 50000)

//

import sys
import time

from PyQt4 import QtNetwork, QtCore
from optparse import OptionParser

class Server(object):

    def __init__(self, port):

        self.port = port

        try:
            self.socket = QtNetwork.QUdpSocket()
            self.socket.bind(QtNetwork.QHostAddress.Broadcast, int(self.port), QtNetwork.QUdpSocket.ShareAddress)

            self.socket.readyRead.connect(self.receiver)

        except QtNetwork.QUdpSocket.NetworkError:
            print "EXCEPTION DURING INITIALIZING SERVER'S SOCKET"
            sys.exit(1)

    def receiver(self):
        print "DEBUG: RECEIVE"
        while(self.socket.hasPendingDatagrams()):
            try:
                size = self.socket.pendingDatagramSize()
                msg, host, port = self.socket.readDatagram(size)
            except:
                print "EXCEPTION DURING RECEIVEING AND READING DATAGRAM"
            else:
                print "HOST %s:%s MSG: %s" % (str(host), str(port), str(msg))

    def __del__(self):
        print "DESTRUCTOR"
        self.socket.close()

class Client(object):

    def __init__(self, port):

        self.port = port

        try:
            self.socket = QtNetwork.QUdpSocket()
        except:
            print "EXCEPTION DURING INITIALIZING CLIENT'S SOCKET"

        self.main_loop()

    def main_loop(self):
        for i in range(20):
            self.debug_msg()
            time.sleep(0.5)
        print "EXITING"
        self.socket.close()


    def debug_msg(self):
        msg = "DEBUG"
        self.socket.writeDatagram(msg, QtNetwork.QHostAddress.Broadcast, int(self.port))


if __name__ == "__main__":

    parser = OptionParser()
    parser.add_option("-p", "", action="store", type="string", dest="port")
    parser.add_option("-c", "", action="store_true", dest="client")
    parser.add_option("-s", "", action="store_true", dest="server")

    options, args = parser.parse_args()

    if not (options.server or options.client):
        print "Client/Server not specified. Could not continue..."
        sys.exit(1)

    elif not options.port:
        print "Server's port not specified. Could not continue..."
        sys.exit(1)

    else:

        if options.server:
            serv = Server(options.port)

            App = QtCore.QCoreApplication(sys.argv)
            sys.exit(App.exec_())
        else:
            client = Client(options.port)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:14:31+00:00Added an answer on May 27, 2026 at 10:14 am

    In your client, you are not starting Qt’s event loop. You should allocate an application object and either call exec_ on it and handle the debug_msg calls via timers or you should pump the event loop using QCoreApplication.processEvents().

    Another option is to use flush():

    http://doc.qt.nokia.com/latest/qabstractsocket.html#flush

    bool QAbstractSocket::flush ()

    This function writes as much as possible from the internal write
    buffer to the underlying network socket, without blocking. If any data
    was written, this function returns true; otherwise false is returned.

    Call this function if you need QAbstractSocket to start sending
    buffered data immediately. The number of bytes successfully written
    depends on the operating system. In most cases, you do not need to
    call this function, because QAbstractSocket will start sending data
    automatically once control goes back to the event loop. In the absence
    of an event loop, call waitForBytesWritten() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows application written in C++ that occasionally evaporates. I use the
I've written an application in pyqt4. It is working in linux and i guess
My application written in C# makes use of the MessageQueue class in .NET for
I have an application written with Qt (I use VS + Integrator). Need to
I have a console application written in C# which processes some data then prints
I have an application written in C++ (makes heavy use of templates) that I
I have an application written in ASP.NET 1.1. If I switch IIS to use
I'm modifying an application written in C# that makes heavy-use of multi-threading to play
I have a very data-centric application, written in Python / PyQt. I'm planning to
My application (written in WPF/C#) will monitor a live video source and will need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.