# Echo client program
import socket
import random
import time

HOST = 'localhost'    # The remote host

# to act as a client
PORT = 50018              # The server port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

# to act as a server
myport = 60002  # my port that can be used by the server 
	# ?? only difference among random clients

# APPLICATION
nummoves = 3
j = 0
while(j < nummoves):
   print("Client j is: ", j)
   bidflag = 1
   while(bidflag == 1):
  	s.send(str(myport) + " " + str(int(50*random.random())))
  	print("Have sent data from ", str(myport))
  	data = s.recv(1024)
  	x = data.split(" ")
  	print("Have received response at ", str(myport), " of: ", ' '.join(x))
	if(x[0] != "Not"):
		bidflag = 0
	else:
		time.sleep(2)

   resultflag = 1
   while(resultflag == 1):
  	s.send(str(myport) + " " + str(int(50*random.random())))
  	print("Have sent data from ", str(myport))
  	data = s.recv(1024)
  	x = data.split(" ")
  	print("Have received response at ", str(myport), " of: ", ' '.join(x))
	if(x[0] != "Not"):
		resultflag = 0
		# would do other processing on x depending on the result
	else:
		time.sleep(2)
   j+= 1


