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 8368169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:19:28+00:00 2026-06-09T13:19:28+00:00

I’m writing a simple IRC server and client GUI using wxPython. In my application,

  • 0

I’m writing a simple IRC server and client GUI using wxPython. In my application, I had two threads running: One for the GUI, and one for the socket connections required to send and receive information. So far, I believe that I am successfully connecting to the server with the client application, but I am seeing no messages processed. I tried using my client with another TCP listener application and I was able to send a message successfully. I believe the problem lies in the way I have set up the GUI. Here is my code for the serverside application (apologies for any awkward spacing)

I have a feeling the problem lies within the bootUp() function..

#!/usr/bin/python

import wx
import socket
import threading
from threading import Thread

ip = ""
port = 0
backlog = 5

chatText = ""

class relayServerGUI(wx.Frame):
def __init__(self, parent, id):
    wx.Frame.__init__(self, parent, id, "Enter IP address", size = (600, 600))
    orciPanel = wx.Panel(self)
    relayChat = wx.TextCtrl(orciPanel, 0, chatText, (50, 50), (500, 500),style              = wx.TE_MULTILINE)
    portInput = wx.TextEntryDialog(None, "Enter Port: ", "")
    if portInput.ShowModal() == wx.ID_OK:
        global port
        port = int(portInput.GetValue())
        thread2()       

def relayInterpretor():
    socketRelay = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socketRelay.bind((ip, port))
    socketRelay.listen(backlog)
    client, address = socketRelay.accept()

    while 1:
                    relayData = client.recv(1024)
                    global chatText
                    chatText += (relayData)
                    client.send(relayData)


def bootUP():
if __name__ == "__main__":
    relayApplication = wx.PySimpleApp()
    relayFrame = relayServerGUI(parent = None, id = -1)
    relayFrame.Show()
    relayApplication.MainLoop()

    while 1:
        relayChat.Clear()
        relayChat.AppendText(chatText)

Thread(target = bootUP).start()
def thread2():
    Thread(target = relayInterpretor).start()

EDIT: relayChat is where the messages would, ideally, be displayed. I set it to copy chatText, a global string variable so I would not have to delve into cross-threading.

  • 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-06-09T13:19:28+00:00Added an answer on June 9, 2026 at 1:19 pm

    I am not very fluent in wx, but I think this problem isn’t very specifically wx related anyways. I see two possible issues here.

    First, you are sharing a string between threads to communicate text to the relayChat widget, which is usually a very bad approach. There should be a way for your to emit an event in wx from the thread, so that the event loop will pick it up in the main thread and run a handler that updates the widget.

    Secondly, the event loop…

    relayApplication.MainLoop()
    

    That is a blocking call. Your application enters the event loop, so this following code is not getting executed:

    while 1:
        relayChat.Clear()
        relayChat.AppendText(chatText)
    

    Again, this ties back into the first point. When the socket in the thread receives some data, it should be emitting an event with that data, so the main gui thread can properly call a handler that will append to your widget.

    Update

    Referencing this question on how to emit custom wx events, you could probably fix it like this:

    from wx.lib.newevent import NewEvent
    
    ChatTextEvent, EVT_CHATTEXT = NewEvent()
    
    class relayServerGUI(wx.Frame):
        def __init__(self, parent, id):
            ...
            # make sure to save a ref to your chat widget
            self.relayChat = wx.TextCtrl(orciPanel, 0, chatText, (50, 50), (500, 500),style              = wx.TE_MULTILINE)
            self.Bind(EVT_CHATTEXT, self.newChatTextEvent)
            ...
            thread2(self)
    
        def newChatTextEvent(self, event):
            self.relayChat.AppendText(event.data)
    
    
    def relayInterpretor(wxObject):
       ...
       while 1:
          ...
          # wxObject needs to be an instance of relayServerGUI
          wx.PostEvent(wxObject, ChatTextEvent(data=relayData))
    
    def thread2(wxObject):
        Thread(target = relayInterpretor, args=(wxObject,)).start()    
    

    *Note: I am not 100% on that syntax. Try it out. It may need a slight tweak.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.