Advertisement
Guest User

server

a guest
Mar 30th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1.  
  2. import socket
  3. import telepot
  4.  
  5. bot=telepot.Bot("1094264182:AAFw73EgNsbAFzmGkB2icSSGJ9TyW8FAqcM")
  6.  
  7.  
  8. def server_program():
  9.     # get the hostname
  10.     host = socket.gethostname()
  11.     port = 80  # initiate port no above 1024
  12.  
  13.     server_socket = socket.socket()  # get instance
  14.     # look closely. The bind() function takes tuple as argument
  15.     server_socket.bind((host, port))  # bind host address and port together
  16.  
  17.     # configure how many client the server can listen simultaneously
  18.     server_socket.listen(2)
  19.     conn, address = server_socket.accept()
  20.     conn.send("شما متصل هستي".encode())
  21.     # accept new connection
  22.     print("Connection from: " + str(address))
  23.     while True:
  24.         # receive data stream. it won't accept data packet greater than 1024 bytes
  25.         data = conn.recv(1024).decode()
  26.         #conn.send('شما متصل شديد'.encode())  # send data to the client
  27.         #if not data:
  28.             # if data is not received break
  29.         #    break
  30.         bot.sendMessage('@test_chanel_10',text=data)
  31.         print("from connected user: " + str(data))
  32.         #data = input(' -> ')
  33.         conn.send(data.encode())  # send data to the client
  34.  
  35.     conn.close()  # close the connection
  36.    
  37.  
  38. if __name__ == '__main__':
  39.     server_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement