# Example 2: Server2.py
# CSC 249 Class example, 
# J Cardell, Feb 13, 2017

# You need to have two different processes on your
# computer to be able to have the client contact
# the server - at a different process number. 
# * Run the client *after* the server is running

# You could run the server from a terminal window
# and the client from Idle. Open the terminal,
# navigate to the correct folder with "cd" and run:
# $ python ./SocketsEx2_server.py

from socket import *

s = socket()         # Create a socket object 
host = gethostname() # Get local machine name 
port = 12345         # Assign a port number 

s.bind((host, port)) # Bind to the port 
print ("Server host is ", host) 

s.listen(1)          # Wait for client conx
while True: 
	c, addr = s.accept() # conx to client 
	print ('Got connection from', addr)    
	c.send('Thank you for connecting') 
	c.close()       # Close the connection
