-2

I found this code on github.

import socket
import threading

# Choosing Nickname
nickname = input("Choose your nickname: ")

# Connecting To Server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 1122))

There is additional code, and a script for the server. However I didn't think it necessary. Is this chatroom LAN based, or could it work anywhere provided both the client and server were connected to the web.

Also, here is the start of the server script.

# Connection Data
host = '127.0.0.1'
port = 1122

# Starting Server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host, port))
server.listen()

Could you please explain what host and port refer to? Thank you!

SetAsync
  • 72
  • 8
  • 1
    Stack Overflow is not intended to replace existing tutorials or documentation, and is not a way to have research, design or coding work done for you. – martineau Mar 02 '21 at 16:17

1 Answers1

0

In simple terms,

Allows a client and a server communicate with each other on IP 127.0.0.1 and port 1122.

LinuxUser
  • 635
  • 1
  • 7
  • 19
  • Would the client and server have to be connected on a LAN? – SetAsync Mar 02 '21 at 16:24
  • 1
    @SetAsync Not necessary. Client and servers on either LAN or WAN should be able to use sockets and have persistent communication established with each other. Check out if you need help how clients and servers can communicate over WAN: https://stackoverflow.com/questions/35384437/socket-connection-over-internet-in-python – LinuxUser Mar 02 '21 at 16:34