예제 #1
0
파일: server.py 프로젝트: ajaygc95/advPy
def server_program():
    # get the hostname
    scrape = Scrape()
    scrape.data_list()

    host = socket.gethostname()
    port = 5000  # initiate port no above 1024

    server_socket = socket.socket()  # get instance
    server_socket.bind((host, port))  # bind host address and port together

    # configure how many client the server can listen simultaneously
    server_socket.listen(1024)
    conn, address = server_socket.accept()  # accept new connection
    print("Connection from: " + str(address))

    while True:
        # receive data stream. it won't accept data packet greater than 1024 bytes
        data = conn.recv(1024).decode()
        print(data)

        if not data:
            # if data is not received break
            break
        print("from connected user: " + str(data))
        data = input(' -> ')
        conn.send(data.encode())  # send data to the client

    conn.close()  # close the connection
예제 #2
0
 def drop_down(self):
     self.window.geometry("500x500")
     self.window.title("Choose Country to Graph ..")
     Label(text="").pack()
     Label(text="Select Country").pack()
     Label(text="").pack()
     scrape = Scrape()
     list1 = scrape.data_list()
     print(list1)
     clicked = StringVar()
     clicked.set(list1[0])
     drop = OptionMenu(self.window, clicked, *list1, command=self.selecter)
     drop.pack()
     self.window.mainloop()
예제 #3
0
    def Connect(self):
        # configure how many client the server can listen simultaneously
        print("server is started and listening on port >>>>>>>>", self.port)
        self.server_socket.listen(5)
        conn, address = self.server_socket.accept()
        print("Connection from: " + str(address))

        while True:
            print("Looping while loop")
            data = conn.recv(1024).decode()
            if not data:
                # if data is not received break
                break
            print("Country Selected : ", data)
            scrape = Scrape()
            scrape.data_list()
            business = Business()
            country_data = business.countryData(data)
            print(type(country_data))
            msg = pickle.dumps(country_data)
            print("done pickling")
            conn.send(msg)
            print("DATA SENT TO THE CLIENT.... ")
예제 #4
0
port = 50000                    # Reserve a port for your service every new transfer wants a new port or you must wait.
s = socket.socket()             # Create a socket object
host = socket.gethostname()   # Get local machine name
s.bind((host, port))            # Bind to the port
s.listen(5)                     # Now wait for client connection.

print('Server listening....')

while True:
    conn, addr = s.accept()     # Establish connection with client.
    print('Got connection from', addr)
    data = conn.recv(1024)
    print('Server received', repr(data))
    scrape = Scrape()
    scrape.data_list()
    business = Business()
    country_data = business.countryData(data)
    l = pickle.dumps(country_data)


    # filename='dog.jpg' #In the same folder or path is this file running must the file you want to tranfser to be
    # f = open(filename,'rb')
    # l = f.read(1024)

    while (l):
        conn.send(l)
        print('Sent ',repr(l))
        l = f.read(1024)

    print('Done sending')