Skip to content

Commit

Permalink
Update severside_chat.py
Browse files Browse the repository at this point in the history
  • Loading branch information
krrish-v authored Jun 12, 2022
1 parent f343a57 commit 58dd8dd
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions BLOCK/severside_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
import socket
import select
import sys
'''Replace "thread" with "_thread" for python 3'''
from thread import *

"""The first argument AF_INET is the address domain of the
socket. This is used when we have an Internet Domain with
any two hosts The second argument is the type of socket.
SOCK_STREAM means that data or characters are read in
a continuous flow."""

from thread_ import *

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

Expand Down Expand Up @@ -80,23 +75,14 @@ def broadcast(message, connection):
# if the link is broken, we remove the client
remove(clients)

"""The following function simply removes the object
from the list that was created at the beginning of
the program"""

def remove(connection):
if connection in list_of_clients:
list_of_clients.remove(connection)

while True:

"""Accepts a connection request and stores two parameters,
conn which is a socket object for that user, and addr
which contains the IP address of the client that just
connected"""
conn, addr = server.accept()

"""Maintains a list of clients for ease of broadcasting
a message to all available people in the chatroom"""
list_of_clients.append(conn)

# prints the address of the user that just connected
Expand Down

0 comments on commit 58dd8dd

Please sign in to comment.