![]() This association with an address must be performed with the bind() system call before the socket can accept connections to other hosts It is only given a protocol family, but not assigned an address. You need a specific port only if you need your client to act as a server, if you don't call bind it will create a random port no ranging from (0 - 1023 are reserved) 1024 - 65535 (if I remember correctly) and that will be Source Port in the UDP Packet, Source Address is the Address where client runs.Īccording to Berkley Sockets bind() assigns a socket to an address. Why do you need to bind to local address of the client? Will the client act as a server too at any point? If not there is no need to bind the client at all. # UDP, each may be from a different source and it's # where they came from in each case (as this is ![]() # Report on all data packets received and Print "Connection timed out for Packet #", totalPings # adding bind here even though it's UDP makes timeout work,Įlapsed = ((time.clock() - start) * 1000) UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) I could hand it in right now and get an A, but I want to understand why the timeout function does not work.ĮDIT: To clarify an issue, the use of Bind in the client was after seeing the server code had it before I realized UDP doesn't need it, but it happened to make the timeout function work properly, but breaks the normal operation.Ĭould the ttimeout() declaration only work for TCP maybe?Ĭlient Code (which has the timeout): import socketĭata = "Re-verify our range to target. Note: Code is not ideal, but this is a networking theory class and not a programming class. ![]() But if it does not bind to the socket, the timeout system fails (this being tested by turning off the server, in which all ten timeouts get printed immediately and at once). In the code represented below, the communication with server running on same machine is successful, but only when the client does not bind to the socket. (e.g: some undocumented reason that Python doesn't like client/server on same machine etc) I'm not looking for a functional code answer (that'd be cheating), but rather why what I have is broken. It might just be a quirk in Python but I'd like to confirm it before I document it. I can't seem to figure out why, but it has to do with the bound socket. So I'm making a basic "ping" application using UDP for an assignment, and everything is working except the implementation of ttimeout().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |