473,396 Members | 1,861 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,396 software developers and data experts.

Problems Drawing Over Network

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/Coo.../Recipe/511435

also the original drawing application I am using
http://aspn.activestate.com/ASPN/Coo.../Recipe/511436

Cheers

I appreciate any help

ty

Andrew Evans
May 4 '07 #1
1 1765
Andrew schrieb:
Hello Everyone
[snipped stuff]
Sorry not being helpful, but I suggest you post a minimal sample of your
code demonstrating your program.

cheers
Paul
May 5 '07 #2

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

Similar topics

2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
1
by: hledman | last post by:
Hello, Beginner here reading through murach's c# book and come to a point where the book doesn't give a good example of what they want you to do in the exercise. I've created an array with 5...
0
by: monfu | last post by:
Dear all I have the following code:- System.Drawing.Image src_image = System.Drawing.Image.FromStream(imgStream); Bitmap bitmap = new Bitmap(image_width, image_height,...
4
by: john | last post by:
I'm having some Interop problems. I really need someone's help on this, i'm running out of ideas. I have upgraded my Data access controls to the latest ver. Now then i have a form with these...
2
by: Rene | last post by:
Hi all i need some help. i try to send mail with the following code. Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click Dim...
2
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I...
6
by: Yehia A.Salam | last post by:
Hello, I'm trying to create my own control derived from ScrollableControl public partial class qViewer : ScrollableControl{ public qViewer() { VScroll = true; AutoScroll = true; } ... }
9
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
1
by: =?Utf-8?B?Q2hyaXN0aWFuIFdlaW5lcnQ=?= | last post by:
Hello, I currently fight with a problem during the derivative of WinForm controls. In Visual Studio I created a new User Control. This control is derived from the DataGridView of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.