Python Forum
Host and port problems for UDP chat server - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Host and port problems for UDP chat server (/thread-3235.html)



Host and port problems for UDP chat server - YevesDraco - May-07-2017

While coding a chat server, I have encountered a problem when trying to bind the host IP and the port to the socket.

The socket doesn't want to read the host IP (which is just the standard loop-back 127.0.0.1) as a string, float or int.
Any help?
Here is the code in Python 3.5

host = ("127.0.0.1")

port = ("5000")

clients = []

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((float(host), int(port)))


(BTW this is the first time I have EVER tried to code something like this)


RE: Host and port problems - Larz60+ - May-07-2017

You are specifying UDP not TCP/IP is this what you wanted?
for TCP/IP change the SOCK_DGRAM to SOCK_STREAM


RE: Host and port problems - YevesDraco - May-07-2017

(May-07-2017, 04:31 PM)Larz60+ Wrote: You are specifying UDP not TCP/IP is this what you wanted?
for TCP/IP change the SOCK_DGRAM to SOCK_STREAM

It's a UDP server. The problem is in the host and port variables or the line:

s.bind((float(host), int(port)))