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

  • Home
  • SEARCH
  • 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 7076023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:14:54+00:00 2026-05-28T06:14:54+00:00

I have written a program that in the client section an error occures frequently,

  • 0

I have written a program that in the client section an error occures frequently, I think the error comes from the socket function in client.py. What should I do?

server.py :

# This is my server code , this code has no problems
import asyncore
import socket

clients = {}

class MainServerSocket(asyncore.dispatcher):
    def __init__(self, port):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.bind(('',port))
        self.listen(5)
    def handle_accept(self):
        newSocket, address = self.accept( )
        clients[address] = newSocket
        print "Connected from", address
        SecondaryServerSocket(newSocket)

class SecondaryServerSocket(asyncore.dispatcher_with_send):
    def handle_read(self):
        receivedData = self.recv(8192)
        if receivedData:
            every = clients.values()
            for one in every:
                one.send(receivedData+'\n')
        else: self.close( )
    def handle_close(self):
        print "Disconnected from", self.getpeername( )
        one = self.getpeername( )
        del clients[one]

MainServerSocket(21567)
asyncore.loop( )

client.py:

from PyQt4 import QtGui , QtCore
from socket import *
import thread
import sys

HOST = 'localhost'
PORT = 21567
BUFSIZE = 1024
ADDR = (HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.socket()

        roomLabel = QtGui.QLabel('room')

        self.browser = QtGui.QTextBrowser()
        self.browser.backwardAvailable

        self.textEdit = QtGui.QTextEdit()
        self.textEdit.setMaximumSize(QtCore.QSize(400,60))
        #4 edit line
        self.connect(self.browser, QtCore.SIGNAL("returnPressed()"),self.callback)

        SendButton = QtGui.QPushButton('Send')
        SendButton.setMaximumSize(QtCore.QSize(400,60))
        SendButton.clicked.connect(self.callback)




        layoutINlayout = QtGui.QHBoxLayout()
        layoutINlayout.addWidget(self.textEdit)
        layoutINlayout.addWidget(SendButton)


        widget = QtGui.QWidget()
        self.setCentralWidget(widget)

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.browser)

        mainwindow = QtGui.QVBoxLayout()
        mainwindow.addLayout (self.layout )
        mainwindow.addLayout (layoutINlayout )

        widget.setLayout(mainwindow)
        self.setWindowFlags(QtCore.Qt.WindowTitleHint )

    def callback(self, event):

        message = self.textEdit.toPlainText()
        tcpCliSock.send(message)



    def add(self, data):
        self.browser.setText(data)


    #i think the error comes from socket func:
    def socket(self):

        def loop0():
            while 1:
                print '1'
                data = tcpCliSock.recv(BUFSIZE)
                if data: self.add(data)

        thread.start_new_thread(loop0, ())


if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    app.setStyle('chat')


    window = MainWindow()
    window.setWindowTitle("pro IJ cracker v2")
    window.setWindowIcon(QtGui.QIcon("img/go.png"))
    window.show()
    sys.exit(app.exec_())
  • 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-28T06:14:54+00:00Added an answer on May 28, 2026 at 6:14 am

    My suggestions are to

    1) Use QThread

    2) Do not directly modify widgets in your main thread from another thread. Instead, emit a signal from your QThread each time there is data.

    Also for some quick information as to WHY your current thread setup is crashing try just wrapping and printing the exception:

        def loop0():
            while 1:
                print '1'
                try:
                    data = tcpCliSock.recv(BUFSIZE)
                    if data: self.add(data)
                except Exception, e:
                    print "ERROR:", e
                    raise
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an ActionScript client program that tries to connect to a local
I have a client program written in .NET 2.0, that connects to the web
I have written a program that uses webDAV to download documents from a sharepoint
I have written a program that will etablish a network connection with a remote
I have written a program that uses qhttp to get a webpage. This works
I have written a java program that is actually works as a gui to
I have written a c# program that calls a c++ dll that echoes the
Below I have written a sample program that I have written to learn about
I have a PHP program that has been written keeping in mind a single
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL

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.