please help me to debud my local chat network program

M

Minh Dang

Hello everybody, i am doing my project: local network chat using python
here is my file
http://www.mediafire.com/?cc2g9tmsju0ba2m
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.
 
T

Terry Reedy

Hello everybody, i am doing my project: local network chat using python
here is my file
http://www.mediafire.com/?cc2g9tmsju0ba2m

I am not familiar with .rar files and whether I can open them. Better to
upload a standard .zip.
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())

sys.exit is not usually necessary. Just 'main()' should be sufficient.
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

The broadcastIP, which you defined elsewhere, whatever it is, is not
valid for udpSock, also defined elsewhere.
 
C

Chris Angelico

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
 
C

Chris Angelico


Thanks! That's a distinct improvement :)

That code doesn't exactly match the traceback, though; there's
client.py not pclient.py and the line numbers don't match. So I have
to just guess that the error is the same. However, I can see an
immediate problem.

def broadcast():
broadcastIP = "<broadcast>"
broadcastPort = 9999

That's not a valid broadcast IP :)

I think you probably want to bind to "" (aka "any address").

ChrisA
 
M

Minh Dang

ok, in client.py, i change broadcastIP = "broadcast" to broadcastIP = "127.0.0.1" but there are some bugs
sys.exit(main())
rQueue, wQueue, xQueue = select.select(inputs, [], [])
 
C

Chris Angelico

but, how can I fix it?

I can't say that for sure, but did you read the bit at the end of my
last post beginning "I think you probably want"? Try doing that, see
what happens.

ChrisA
 
M

Minh Dang

ok, in client.py, i change broadcastIP = "broadcast" to broadcastIP = "127.0.0.1",it's ok, but there are some bugs
sys.exit(main())
rQueue, wQueue, xQueue = select.select(inputs, [], [])
 
M

Minh Dang

ok, in client.py, i change broadcastIP = "broadcast" to broadcastIP = "127.0.0.1",it's ok, but there are some bugs
sys.exit(main())
rQueue, wQueue, xQueue = select.select(inputs, [], [])
 
M

Minh Dang

yes, still have 2 bugs:
sys.exit(main())
rQueue, wQueue, xQueue = select.select(inputs, [], [])
 
M

Minh Dang

please help me, after changing broadcast, there are 2 bugs:
if __name__ == "__main__":
sys.exit(main())
and

rQueue, wQueue, xQueue = select.select(inputs, [], [])
please help me
 
C

Chris Angelico

please help me, after changing broadcast, there are 2 bugs:
if __name__ == "__main__":
sys.exit(main())
and

rQueue, wQueue, xQueue = select.select(inputs, [], [])
please help me

By "bug", I'm guessing you mean one of two things:

1) The program fails to run, and an exception is given that points to
one of these lines, or
2) The program runs, but does something different from what you expect it to do.

If it's the first, what's the exception? If the second, what do you
expect and what happens?

You need to provide more information. Check out the link I gave you on
how to ask questions; it's very helpful.

ChrisA
 
M

Minh Dang

yes, it's run but appear:
in server: Server is ready.
Accepted connection from ('127.0.0.1', 5000)
End connection from ('127.0.0.1', 5000)
after connected, server close.
in client: Connected to server at 127.0.0.1 : 4000
Traceback (most recent call last):
File "C:\Users\MINH_IT\workspace\project\src\project\client.py", line 303, in <module>
sys.exit(main())
File "C:\Users\MINH_IT\workspace\project\src\project\client.py", line 60, in main
rQueue, wQueue, xQueue = select.select(inputs, [], [])
OSError: [WinError 10038] An operation was attempted on something that is not a socket
there are 2 problems.
 
M

Minh Dang

yes, it's run but appear:
in server: Server is ready.
Accepted connection from ('127.0.0.1', 5000)
End connection from ('127.0.0.1', 5000)
after connected, server close.
in client: Connected to server at 127.0.0.1 : 4000
Traceback (most recent call last):
File "C:\Users\MINH_IT\workspace\project\src\project\client.py", line 303, in <module>
sys.exit(main())
File "C:\Users\MINH_IT\workspace\project\src\project\client.py", line 60, in main
rQueue, wQueue, xQueue = select.select(inputs, [], [])
OSError: [WinError 10038] An operation was attempted on something that is not a socket
there are 2 problems.
 
C

Chris Angelico

File "C:\Users\MINH_IT\workspace\project\src\project\client.py", line 60, in main
rQueue, wQueue, xQueue = select.select(inputs, [], [])
OSError: [WinError 10038] An operation was attempted on something that is not a socket

Have a look at that line of code - specifically, look at what's in
inputs. One of them perhaps isn't a socket. Tip: The print function is
your friend.

ChrisA
 
J

Jorgen Grahn

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.

Or a Git repository at github.com or similar.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top