472,779 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Twisted/wxPython Problem...


I am relatively new to Python, and am learning it as part of a

Im currently undertaking a project to create an IM server and IM gui

I have a very basic server, and a basic gui client. I can get my
client to
connect to my server, but cant get it to disconnect or send messages to

I am getting the following error when I click on the 'Disconnect'
button -
AttributeError: 'NoneType' object has no attribute 'loseConnection'

I have attached the code for both the server and the client below this.

I am using the Twisted and wxPython packages, and as previously stated
fairly new to Python so would appreciate any help anyone can offer.



from twisted.internet import reactor
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver

factory = Factory()
#this is a list
factory.transports = []
#this is a dictionary
userNicknames = {}

class SimpleLogger(LineReceiver):

def connectionMade(self):
userNicknames[self.transport.client] = ''
#write to the client
self.transport.write("Welcome to Chris & Pete's chat server!\r\n")
self.transport.write("Please enter your nickname:\r\n")
#prints on the server screen
print 'got connection from', self.transport.client

def connectionLost(self, reason):
who = str(userNicknames.get(self.transport.client)) + '
Disconnected' + '\r\n'
print who
userNicknames[self.transport.client] = ''
for transport in self.factory.transports:
def lineReceived(self, line):
#if the users nickname in the dictionary (userNicknames) is
blank, create a
#value in the dictionary with the line just received.
#if the user already has a nickname then it must be a message
they are writing.
#So instead print out the message
if userNicknames.get(self.transport.client) == '':
#if the username is already in the dictionary someone is
#already using it so ask for another one.
if line in userNicknames.values():
self.transport.write('That nickname is already in use,
please use another:')
userNicknames[self.transport.client] = line
#print userNicknames.items()
message = userNicknames.get(self.transport.client) + '
has joined\r\n'
for transport in self.factory.transports:

message = userNicknames.get(self.transport.client) + ': ' +
line + '\r\n'
for transport in self.factory.transports:

factory.protocol = SimpleLogger

reactor.listenTCP(1234, factory)
from wxPython.wx import *
import wx
from twisted.internet import wxreactor
from twisted.internet import reactor
from twisted.internet.protocol import Protocol, ClientCreator

class imApp(wxApp, Protocol):

def buildMe(self):
frame = wx.Frame(None, title="IM Client", size=(800, 550))

bkg = wx.Panel(frame)

global ipAdd
global portNo
global messages
global newMsg

ipAddLab = wx.StaticText(bkg, -1, 'IP Address: ')
ipAdd = wx.TextCtrl(bkg)
ipAdd.SetToolTipString('Please enter the server IP address
spacer1 = wx.StaticText(bkg, -1, ' ')
portNoLab = wx.StaticText(bkg, -1, 'Port No: ')
portNo = wx.TextCtrl(bkg)
portNo.SetToolTipString('Please enter the port number the
server is using here.')
spacer2 = wx.StaticText(bkg, -1, ' ')
connectButton = wx.Button(bkg, label='Connect')
connectButton.SetToolTipString('Click this button to connect to
the server.')
connectButton.Bind(wx.EVT_BUTTON, self.connectMe)
disconnectButton = wx.Button(bkg, label='Disconnect')
disconnectButton.SetToolTipString('Click this button to
disconnect from the server.')
disconnectButton.Bind(wx.EVT_BUTTON, self.disconnectMe)
messages = wx.TextCtrl(bkg, style=(wx.TE_MULTILINE |
newMsg = wx.TextCtrl(bkg)
sendButton = wx.Button(bkg, label='Send')
sendButton.SetToolTipString('Click this button to send a
message to the server.')
sendButton.Bind(wx.EVT_BUTTON, self.sendMe)

hbox1 = wx.BoxSizer()

hbox1.Add(ipAddLab, proportion=0, flag=wx.EXPAND)
hbox1.Add(ipAdd, proportion=0, flag=wx.EXPAND)
hbox1.Add(spacer1, proportion=0, flag=wx.EXPAND)
hbox1.Add(portNoLab, proportion=0, flag=wx.EXPAND)
hbox1.Add(portNo, proportion=0, flag=wx.EXPAND)
hbox1.Add(spacer2, proportion=0, flag=wx.EXPAND)
hbox1.Add(connectButton, proportion=0, flag=wx.LEFT, border=5)
hbox1.Add(disconnectButton, proportion=0, flag=wx.LEFT,

hbox2 = wx.BoxSizer()
hbox2.Add(newMsg, proportion=1, flag=wx.EXPAND | wx.LEFT |
wx.LEFT | wx.LEFT, border=5)
hbox2.Add(sendButton, proportion=0, flag=wx.LEFT, border=5)

vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox1, proportion=0, flag=wx.EXPAND | wx.ALL,
vbox.Add(messages, proportion=1, flag=wx.EXPAND | wx.LEFT |
wx.LEFT | wx.LEFT, border=5)
vbox.Add(hbox2, proportion=1, flag=wx.EXPAND | wx.ALL,


return true

def sendMe(self, e):
msg = newMsg.GetValue() + '\n'

def disconnectMe(self, e):
messages.WriteText('Disconnecting from server...\n')

def connectMe(self, e):
messages.WriteText('Connecting to server...\n')
c = ClientCreator(reactor, imApp)
ip = str(ipAdd.GetValue())
port = int(portNo.GetValue())
c.connectTCP(ip, port)

def mainProg():
app = imApp(0)

if __name__ == '__main__':

Apr 24 '06 #1
1 2726
PeterG wrote:

I am relatively new to Python, and am learning it as part of a

Im currently undertaking a project to create an IM server and IM gui

I have a very basic server, and a basic gui client. I can get my
client to
connect to my server, but cant get it to disconnect or send messages to

I am getting the following error when I click on the 'Disconnect'
button -
AttributeError: 'NoneType' object has no attribute 'loseConnection'

It seems that your client inherits from two classes, but doesn't invoke
their respective constructors. That makes python only call the first
classes constructor, as this simple experiment shows:

class A(object):
def __init__(self):
print "I'm A"

class B(object):
def __init__(self):
print "I'm B"
class C(A,B):

-> I'm A
so - create a constructor, invoke both constructors of your super-classes
either explicitly or using super (make sure you understand super!)

Apr 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Paul Moore | last post by:
I hit a problem yesterday with my mail connection. In a desparate attempt to understand what was going on, I wanted to log the connection traffic. After a bit of searching, I found a post on c.l.p...
by: mir nazim | last post by:
hi, i m planning to start writing intranet applications and want ur real cool advices for choosing the correct platform. the choice is between the three: 1. Twisted 2. Medusa 3. Zope (i do...
by: marchew | last post by:
hi, i have a problem integrating wxPython and Twisted under Win32. my application consumes 40-50% of CPU resources when wxFrame is visible and reactor (twisted) is running. i looked at...
by: Taki Jeden | last post by:
Hi Anybody used wxPython with twisted? I started putting together a Twisted-based app with wx GUI, and the widgets just don't work - some controls do not show up etc. - at least on my system....
by: flupke | last post by:
Hi, previously i made an application that used sockets to do some network based processing. My next app is again going to be a client/server app and i wanted to see if i can't find an easier...
by: Daniel Bickett | last post by:
Hello, I am writing an application using two event-driven libraries: wxPython, and twisted. The first problem I encountered in the program is the confliction between the two all-consuming...
by: SeSe | last post by:
Hi, I am new to Twisted. I use a Twisted 1.3.0 on MS Windows XP Home Edition, my python version is 2.3 I try the TCP echoserv.py and echoclient.py example. But the client always fail with...
by: Christopher Subich | last post by:
I'm building an application that makes several user-specified internet connections; twisted meets my needs more or less perfectly. I'm running into a problem, however, in that twisted is not...
by: qvx | last post by:
I want to start twisted app from another GUI application and not via twistd. It works fine when started via twistd (1 & 2) but not when I try to start it manually (1 & 3) - nothing is listening...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.