A
Andrew
Hello Everyone
I am receiving an error in an application I am working on. The
application when its done will be a Dungeons and Dragons Network game. I
am having problems with the Networked Canvas basically for drawing the
dungeon maps
If I initialize two of the Tkinter Canvas widgets with in the same
window I can draw across the network, however if I open a second
instance of the Application and initialize the canvas, on windows I recv
a "Software has caused a connection abort error", on Linux I recv a
broken pipe message
I am wondering how to go about fixing this I have spent the last 4 days
trying to figure it
Any ideas would be appreciated
Cheers
###CODE###
#CLIENT
import random
import time
from Tkinter import *
import string
import sys
import Image
import ImageTk
import JpegImagePlugin
from threading import *
import socket
import spots
import time
import thread
Image.initialized = 1
HOST = '24.207.81.142'
PORT = 8080
PORT2 = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
PORT2 = 8888
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((HOST, PORT2))
ZSP = spots.ZSP(server)
def main():
global hold
hold = []
global fill
fill = '#000000'
connect()
root = Tk()
root.title('Graphics')
root.resizable(False, False)
upper = LabelFrame(root, text='Global Canvas')
lower = LabelFrame(root, text='Their Canvas')
global draw
draw = Canvas(upper, bg='#ffffff', width=400, height=300,
highlightthickness=0)
global look
#look = Canvas(lower, bg='#ffffff', width=400, height=300,
highlightthickness=0)
cursor = Button(upper, text='Cursor Color', command=change_cursor)
canvas = Button(upper, text='Canvas Color', command=change_canvas)
draw.bind('<Motion>', motion)
draw.bind('<ButtonPress-1>', press)
draw.bind('<ButtonRelease-1>', release)
draw.bind('<Button-3>', delete)
upper.grid(padx=5, pady=5)
lower.grid(padx=5, pady=5)
draw.grid(row=0, column=0, padx=5, pady=5, columnspan=2)
#look.grid(padx=5, pady=5)
cursor.grid(row=1, column=0, padx=5, pady=5, sticky=EW)
canvas.grid(row=1, column=1, padx=5, pady=5, sticky=EW)
root.mainloop()
def connect():
thread.start_new_thread(processor, ())
##def start_server():
## global ZSP
## server = socket.socket()
## server.bind(('', PORT))
## server.listen(1)
## ZSP = spots.ZSP(server.accept()[0])
def processor():
while True:
(func, args, kwargs) = ZSP.recv()
getattr(draw, func)(*args, **kwargs)
time.sleep(0.1)
def call(func, *args, **kwargs):
ZSP.send((func, args, kwargs))
################################################################################
def change_cursor():
global fill
color = tkColorChooser.askcolor(color=fill)[1]
if color is not None:
fill = color
def change_canvas():
color = tkColorChooser.askcolor(color=draw['bg'])[1]
if color is not None:
draw['bg'] = color
draw.config(bg=color)
call('config', bg=color)
################################################################################
def motion(event):
if hold:
hold.extend([event.x, event.y])
event.widget.create_line(hold[-4:], fill=fill, tag='TEMP')
call('create_line', hold[-4:], fill=fill, tag='TEMP')
def press(event):
global hold
hold = [event.x, event.y]
def release(event):
global hold
if len(hold) > 2:
event.widget.delete('TEMP')
event.widget.create_line(hold, fill=fill, smooth=True)
call('delete', 'TEMP')
call('create_line', hold, fill=fill, smooth=True)
hold = []
def delete(event):
event.widget.delete(ALL)
call('delete', ALL)
################################################################################
class App:
def __init__(self, master):
#initialize socket variables for theclient
self.thread1 = Thread(target=self.run)
self.thread1.start()
self.frameH = frameH = Frame(master, background="#ffffff")
self.labelH = Label(frameH, image=fri)
self.labelH.pack(side=TOP)
frameH.pack()
self.framettext = Frame(master)
self.scrollbar = Scrollbar(self.framettext)
self.scrollbar.pack(side=RIGHT, fill=Y, expand=TRUE)
self.textbox = Text(self.framettext)
self.textbox.pack(fill=BOTH, expand=True)
self.textbox.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.textbox.yview)
self.framettext.pack(fill=BOTH, expand=True)
self.frame = Frame(master)
self.frame.pack(fill=X, expand=True)
self.send=Button(self.frame, text='Send Message',
command=self.send)
self.send.pack(side=LEFT)
self.draw=Button(self.frame, text='Dungeon Canvas',
command=self.openCanvas)
self.draw.pack(side=LEFT)
self.d20=Button(self.frame, text='D20', command=self.d20roll)
self.d20.pack(side=LEFT)
self.sendtext=Entry(self.frame)
self.sendtext.pack(side=LEFT, fill=X, expand=True)
################################################################################
def d20roll(self):
self.rand = random.randrange(1, 20)
rs = str(self.rand)
self.d20text = "d20 Roll " + rs
s.send(self.d20text)
self.textbox.insert(END, self.d20text)
def openCanvas(self):
main()
def send(self):
self.sendit = self.sendtext.get()
if self.sendit == "":
pass
else:
s.send(self.sendit)
self.textbox.insert(END, self.sendit + "\n")
self.sendtext.delete(0, END)
def run(self):
while 1:
data=s.recv(1024)
app.textbox.insert(END, str(data) + "\n")
time.sleep(0.1)
#################################
root = Tk()
root.wm_resizable(0, 0)
root.wm_iconbitmap("shinobi.ico")
frmimg = Image.open("banner.jpg")
fri = ImageTk.PhotoImage(frmimg)
classtitle="Tech Shinobi Chat 1.0"
root.option_readfile("optionDB")
root.title(classtitle)
root.geometry('%dx%d+%d+%d' % (500,380,0,0))
app = App(root)
root.mainloop()
s.close()
###END CODE###
That is the client now here is the server
###CODE###
#!/usr/bin/env python
#SERVER
import socket, traceback, os, sys
from threading import *
import spots
host = '' # Bind to all interfaces
port = 8888
def handlechild():
while 1:
data = ZSP.recv()
if not len(data):
break
ZSP.send((data))
# Set up the socket.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)
while 1:
try:
ZSP = spots.ZSP(s.accept()[0])
except KeyboardInterrupt:
raise
except:
traceback.print_exc()
continue
t = Thread(target=handlechild)
t.setDaemon(1)
t.start()
heres is a link to the spots module I am using
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511435
also the original drawing application I am using
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511436
Cheers
I appreciate any help
ty
Andrew Evans
I am receiving an error in an application I am working on. The
application when its done will be a Dungeons and Dragons Network game. I
am having problems with the Networked Canvas basically for drawing the
dungeon maps
If I initialize two of the Tkinter Canvas widgets with in the same
window I can draw across the network, however if I open a second
instance of the Application and initialize the canvas, on windows I recv
a "Software has caused a connection abort error", on Linux I recv a
broken pipe message
I am wondering how to go about fixing this I have spent the last 4 days
trying to figure it
Any ideas would be appreciated
Cheers
###CODE###
#CLIENT
import random
import time
from Tkinter import *
import string
import sys
import Image
import ImageTk
import JpegImagePlugin
from threading import *
import socket
import spots
import time
import thread
Image.initialized = 1
HOST = '24.207.81.142'
PORT = 8080
PORT2 = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
PORT2 = 8888
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((HOST, PORT2))
ZSP = spots.ZSP(server)
def main():
global hold
hold = []
global fill
fill = '#000000'
connect()
root = Tk()
root.title('Graphics')
root.resizable(False, False)
upper = LabelFrame(root, text='Global Canvas')
lower = LabelFrame(root, text='Their Canvas')
global draw
draw = Canvas(upper, bg='#ffffff', width=400, height=300,
highlightthickness=0)
global look
#look = Canvas(lower, bg='#ffffff', width=400, height=300,
highlightthickness=0)
cursor = Button(upper, text='Cursor Color', command=change_cursor)
canvas = Button(upper, text='Canvas Color', command=change_canvas)
draw.bind('<Motion>', motion)
draw.bind('<ButtonPress-1>', press)
draw.bind('<ButtonRelease-1>', release)
draw.bind('<Button-3>', delete)
upper.grid(padx=5, pady=5)
lower.grid(padx=5, pady=5)
draw.grid(row=0, column=0, padx=5, pady=5, columnspan=2)
#look.grid(padx=5, pady=5)
cursor.grid(row=1, column=0, padx=5, pady=5, sticky=EW)
canvas.grid(row=1, column=1, padx=5, pady=5, sticky=EW)
root.mainloop()
def connect():
thread.start_new_thread(processor, ())
##def start_server():
## global ZSP
## server = socket.socket()
## server.bind(('', PORT))
## server.listen(1)
## ZSP = spots.ZSP(server.accept()[0])
def processor():
while True:
(func, args, kwargs) = ZSP.recv()
getattr(draw, func)(*args, **kwargs)
time.sleep(0.1)
def call(func, *args, **kwargs):
ZSP.send((func, args, kwargs))
################################################################################
def change_cursor():
global fill
color = tkColorChooser.askcolor(color=fill)[1]
if color is not None:
fill = color
def change_canvas():
color = tkColorChooser.askcolor(color=draw['bg'])[1]
if color is not None:
draw['bg'] = color
draw.config(bg=color)
call('config', bg=color)
################################################################################
def motion(event):
if hold:
hold.extend([event.x, event.y])
event.widget.create_line(hold[-4:], fill=fill, tag='TEMP')
call('create_line', hold[-4:], fill=fill, tag='TEMP')
def press(event):
global hold
hold = [event.x, event.y]
def release(event):
global hold
if len(hold) > 2:
event.widget.delete('TEMP')
event.widget.create_line(hold, fill=fill, smooth=True)
call('delete', 'TEMP')
call('create_line', hold, fill=fill, smooth=True)
hold = []
def delete(event):
event.widget.delete(ALL)
call('delete', ALL)
################################################################################
class App:
def __init__(self, master):
#initialize socket variables for theclient
self.thread1 = Thread(target=self.run)
self.thread1.start()
self.frameH = frameH = Frame(master, background="#ffffff")
self.labelH = Label(frameH, image=fri)
self.labelH.pack(side=TOP)
frameH.pack()
self.framettext = Frame(master)
self.scrollbar = Scrollbar(self.framettext)
self.scrollbar.pack(side=RIGHT, fill=Y, expand=TRUE)
self.textbox = Text(self.framettext)
self.textbox.pack(fill=BOTH, expand=True)
self.textbox.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.textbox.yview)
self.framettext.pack(fill=BOTH, expand=True)
self.frame = Frame(master)
self.frame.pack(fill=X, expand=True)
self.send=Button(self.frame, text='Send Message',
command=self.send)
self.send.pack(side=LEFT)
self.draw=Button(self.frame, text='Dungeon Canvas',
command=self.openCanvas)
self.draw.pack(side=LEFT)
self.d20=Button(self.frame, text='D20', command=self.d20roll)
self.d20.pack(side=LEFT)
self.sendtext=Entry(self.frame)
self.sendtext.pack(side=LEFT, fill=X, expand=True)
################################################################################
def d20roll(self):
self.rand = random.randrange(1, 20)
rs = str(self.rand)
self.d20text = "d20 Roll " + rs
s.send(self.d20text)
self.textbox.insert(END, self.d20text)
def openCanvas(self):
main()
def send(self):
self.sendit = self.sendtext.get()
if self.sendit == "":
pass
else:
s.send(self.sendit)
self.textbox.insert(END, self.sendit + "\n")
self.sendtext.delete(0, END)
def run(self):
while 1:
data=s.recv(1024)
app.textbox.insert(END, str(data) + "\n")
time.sleep(0.1)
#################################
root = Tk()
root.wm_resizable(0, 0)
root.wm_iconbitmap("shinobi.ico")
frmimg = Image.open("banner.jpg")
fri = ImageTk.PhotoImage(frmimg)
classtitle="Tech Shinobi Chat 1.0"
root.option_readfile("optionDB")
root.title(classtitle)
root.geometry('%dx%d+%d+%d' % (500,380,0,0))
app = App(root)
root.mainloop()
s.close()
###END CODE###
That is the client now here is the server
###CODE###
#!/usr/bin/env python
#SERVER
import socket, traceback, os, sys
from threading import *
import spots
host = '' # Bind to all interfaces
port = 8888
def handlechild():
while 1:
data = ZSP.recv()
if not len(data):
break
ZSP.send((data))
# Set up the socket.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)
while 1:
try:
ZSP = spots.ZSP(s.accept()[0])
except KeyboardInterrupt:
raise
except:
traceback.print_exc()
continue
t = Thread(target=handlechild)
t.setDaemon(1)
t.start()
heres is a link to the spots module I am using
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511435
also the original drawing application I am using
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511436
Cheers
I appreciate any help
ty
Andrew Evans