Advertisement
VssA

Socket

Dec 12th, 2023
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import socket
  2. import pandas as pd
  3.  
  4. def get_website(organization_name):
  5.     data = pd.read_csv('organizations.csv')
  6.     website = data[data['Name'] == organization_name]['Website'].values
  7.     return website[0]
  8.  
  9.  
  10. def start_server():
  11.    
  12.     host = "127.0.0.32"
  13.     port = 12345
  14.    
  15.     server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  16.     server_socket.bind((host, port))
  17.     server_socket.listen(1)
  18.  
  19.     while True:
  20.         client_socket, address = server_socket.accept()
  21.         data = client_socket.recv(1024)
  22.         message = data.decode()
  23.         if message == "exit":
  24.             break
  25.         website = get_website(message)
  26.         client_socket.send(website.encode())
  27.         client_socket.close()
  28.  
  29. if __name__ == "__main__":
  30.     start_server()
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement