473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Simple server/client application

MBW
The following code is for a simple server/client asplication that
allows the user to toggle between serve and or client modes and
send/recieve a message however i am getting an Attribute error on my
entry widgets when I try and call get() to get the port and ip address
from those fields, I'm sure it's something simple I haven't grasped...

#START

from Tkinter import *
from socket import *
import sys

class mySCS:
def __init__(self,root):
self.root = root
self.root.title("My Simple Client/Server ")
self.mode = "Server"
self.create_widgets()

self.root.mainloop()
return None

def create_widgets(self):
self.portLbl = Label(self.root,text="Port
number:").grid(sticky=E)
self.AddrLbl = Label(self.root,text="IP
Address:").grid(row=1,sticky=E)
self.myPort =
Entry(self.root,relief=SUNKEN).grid(column=1,row=0 ,sticky=W)
self.myAddress =
Entry(self.root,relief=SUNKEN).grid(row=1,column=1 ,sticky=W)
self.SCSToggle =
Radiobutton(self.root,text="Server",value="Server" ,variable=self.mode).grid(row=2,column=0,sticky=W)
self.SCSToggle =
Radiobutton(self.root,text="Client",value="Client" ,variable=self.mode).grid(row=2,column=1,sticky=W)
self.messageLbl = Label(self.root,text="Message:").grid(row=4)
self.myMessage = Text(self.root,height=6).grid(row=4,column=1)
self.statusLbl = Label(self.root,text="Status:").grid(row=5)
self.myStatus = Text(self.root,height=6).grid(row=5,column=1)
self.myConnect =
Button(self.root,text='Run',command=self.connect). grid(row=6,
columnspan=2)
return None

def connect(self):
Host = self.myAddress.get()
Port = self.myPort.get()

if self.mode == "Server":

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((Host,Port))
sockobj.listen(5)
myStatus.insert("Waiting on Conncetion...\n")
while 1:
connection, address = sockobj.accept()
myStatus.insert('Server connection by', address)
while 1:
data = connection.recv(1024)
if not data: break
self.myStatus.insert('Data Recievced ' +str(data))
connection.send('Echo=>' + data)
connection.close()

if self.mode == "Client":

message = myMessage.get()
if len(sys.argv) > 1:
Host =sys.argv[1]
if len(sys.argv) > 2:
message = sys.argv[2:]

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((Host, Port))

sockobj.send(message)
data = sockobj.recv(1024)
self.myStatus.insert('Client recived:', str(data))

sockobj.close()
return None

if __name__ == "__main__":
root = Tk()
myobj = mySCS(root)

#END

Error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args)
File "C:\Documents and Settings\Matt\My
Documents\work\eclipse\workspace\PSI\View\mySCS.py ", line 30, in
connect
Host = self.myAddress.get()
AttributeError: 'NoneType' object has no attribute 'get'

Oct 24 '05 #1
3 2468
You're calling the grid() method on the Entry object you're
instanciating. Are you sure that the grid() method returns the Entry
object so that you're actually binding it to self.myAddress?

Oct 24 '05 #2

Simon Percivall wrote:
You're calling the grid() method on the Entry object you're
instanciating. Are you sure that the grid() method returns the Entry
object so that you're actually binding it to self.myAddress?


The widget maker should do it in two steps instead of one.
So instead of:

self.myAddress=Entry(self.root,relief=SUNKEN).grid (row=1,column=1,sticky=W)
Make it thus:
self.myAddress = Entry(self.root,relief=SUNKEN) # make it and
keep it here
self.address.grid(row=1,column=1,sticky=W) # grid it here
in the create_widgets method.

Oct 25 '05 #3
MBW
thanks both of you,

I should have realized what was gonig on

Cheers,
Matt

Oct 25 '05 #4

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

Similar topics

5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
10
by: GeekBoy | last post by:
Okay, I have two identical web servers running Windows 2003 web server. I have an ASP.NET application which runs great on one of them. Dedicated IP address, behind our firewall, etc. Everyone's...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
6
by: Marc | last post by:
How could I directly trigger a very simple on localhost and a known port listening server from my internet browser client? Local host means the little server would be running on the client machine,...
1
by: Josema | last post by:
Hi, Im newbie in Sockets, and im trying to make an application to listen from a port, and another to send bytes to this port... I'm using asyncronous sockets, and i have the most of the code...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.