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

How to use Sockets with wxPython?

I am having this problem:
I use Python for my teaching and right now we are trying to implement some
sort of very simple graphical game the pupils can play across the
Internet. For this, we use wxPython.

Now it has turned out that wxPython does not implement wxWidget sockets,
so we have to use Python sockets instead. Implementing a separate thread
for this would be too complicated and I am going to use the wxIdle event
to do the socket processing, as the amount of data sent from one player to
the other is very small.

Could somebody show me, how to use Pythin socket in "polling mode" and
how to achieve this? I am not expecting a complete program, an outline of
the logic woul suffice.

TIA,

--
jb
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 18 '05 #1
4 2853
DH
jblazi wrote:
I am having this problem:
I use Python for my teaching and right now we are trying to implement some
sort of very simple graphical game the pupils can play across the
Internet. For this, we use wxPython.

Now it has turned out that wxPython does not implement wxWidget sockets,
so we have to use Python sockets instead. Implementing a separate thread
for this would be too complicated and I am going to use the wxIdle event
to do the socket processing, as the amount of data sent from one player to
the other is very small.


You might want to use Twisted instead. You need the very latest version
(1.2 or later) for it to work with wxPython:
http://www.twistedmatrix.com/products/twisted

You would use Twisted's wxreactor class. Look at the wxdemo.py file
under site-packages/TwistedDocs/examples/
See also this tutorial (part 2 on game networking) on using Twisted with
pygame: http://sjbrown.ezide.com/games/writing-games.html
Jul 18 '05 #2
On Fri, 12 Mar 2004 15:49:42 -0600, DH wrote:
jblazi wrote:
I am having this problem:
I use Python for my teaching and right now we are trying to implement some
sort of very simple graphical game the pupils can play across the
Internet. For this, we use wxPython.

Now it has turned out that wxPython does not implement wxWidget sockets,
so we have to use Python sockets instead. Implementing a separate thread
for this would be too complicated and I am going to use the wxIdle event
to do the socket processing, as the amount of data sent from one player to
the other is very small.


You might want to use Twisted instead.


Thx, but I can't. If it does not work with the components I already have,
I am having trouble (and then wxPython would be useless as well, which I
do not believe).

--
jb

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 18 '05 #3
> I am having this problem:
I use Python for my teaching and right now we are trying to implement some
sort of very simple graphical game the pupils can play across the
Internet. For this, we use wxPython.

Now it has turned out that wxPython does not implement wxWidget sockets,
so we have to use Python sockets instead. Implementing a separate thread
for this would be too complicated and I am going to use the wxIdle event
to do the socket processing, as the amount of data sent from one player to
the other is very small.

Could somebody show me, how to use Pythin socket in "polling mode" and
how to achieve this? I am not expecting a complete program, an outline of
the logic woul suffice.


I would suggest you stay away from wxIdle events, if only because they
only occur under certain circumstances (in Windows, they seem to only
occur when the mouse is moved over the window).

Start with asyncore, and get everything working properly with that.

When it is working properly, do something like the following for your GUI:

import asyncore
import yourasyncorelibrary

#in the __init__ method of your main window class
#set up the server/clients/whatever

#using the new namespace
self.timer = wx.Timer(self, wx.NewId())
EVT_TIMER(self, self.timer.GetId(), self.SocketPoller)
self.timer.Start(10, wx.TIMER_CONTINUOUS)

def SocketPoller(self, event):
asyncore.poll()

If you properly designed your server and clients, the above should just
work. If you are willing to post information about your architecture or
protocol, I may be able to help you more.

- Josiah
Jul 18 '05 #4
> EVT_TIMER(self, self.timer.GetId(), self.SocketPoller)

Oops, should be:

wx.EVT_TIMER(self, self.timer.GetId(), self.SocketPoller)
Jul 18 '05 #5

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

Similar topics

7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
1
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have...
1
by: James Stroud | last post by:
Hello All, I will soon have an excuse to install a new operating system on my computer. I would like to know exactly what operating system I should have so that I can get wxPython going....
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
4
by: stef | last post by:
hello, I'm trying to move from Delphi to Python (move from MatLab to Python already succeeded, also thanks to this discussion group). From the discussions in this list about "the best" GUI for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.