please help me to debud my local chat network program

Chris Angelico rosuav at gmail.com
Tue Nov 27 23:03:02 EST 2012


On Wed, Nov 28, 2012 at 1:50 PM, Minh Dang <dangbaminh.it at gmail.com> wrote:
> Hello everybody, i am doing my project: local network chat using python
> here is my file
> http://www.mediafire.com/?cc2g9tmsju0ba2m

Hmm. Might I recommend some other means of sharing your code? The
unrar-free utility from the Debian repo won't extract more than the
first file (accounts.txt), and I don't know if that's a problem with
unrar-free or your file. A better-known format like zip or tar.gz
would make things easier.

> when i compile client.py, there is some bug
> Traceback (most recent call last):
> File "C:\Users\MINH_IT\workspace\project\src\project\pclient.py", line 303, in <module>
> sys.exit(main())
> File "C:\Users\MINH_IT\workspace\project\src\project\pclient.py", line 42, in main
> servIP = broadcast()
> File "C:\Users\MINH_IT\workspace\project\src\project\pclient.py", line 79, in broadcast
> udpSock.bind((broadcastIP, broadcastPort))
> OSError: [WinError 10049] The requested address is not valid in its context
> Please help me to debud it, thank so much.

What's the broadcastIP address you're using? (As mentioned above, I
can't see your source code.) Is it the appropriate address for one of
your interfaces?

Broadcast UDP is a bit tricky sometimes. You need to explicitly enable
broadcasting on the socket -  I've not done this in Python but two
seconds with Google suggests that this is needed:

udpSock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

You may have already done this, but I don't know without seeing your code.

My crystal ball tells me that you're trying to bind to a broadcast
address (eg 192.168.0.255). This is incorrect; you need to instead
bind to your own IP address (eg 192.168.0.17). You can probably just
do this:

udpSock.bind(('', broadcastPort))

However, my crystal ball has been playing up a bit lately, so it's
hard to be sure.

ChrisA



More information about the Python-list mailing list