I´m building an app that uses sockets to send and request data between servers, right now I´m trying to send the time. I have a server socket in an Ubuntu VM on Virtualbox:
#ip = '0.0.0.0'
#ip = '127.0.0.1'
ip = '127.0.1.1'
#ip = '10.0.2.15'
port = 8080
data_connection = (ip, port)
max_connections = 3
time_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
time_server_socket.bind(data_connection)
time_server_socket.listen(max_connections)
print("Waiting on %s:%s" %(ip, port))
print(socket.gethostname())
print(socket.gethostbyname(socket.gethostname()))
while True:
time_st = time.gmtime(time.time())
client, address = time_server_socket.accept()
print("Connection %s:%s" %(address[0], address[1]))
data = client.recv(4096)
print("Direccion: " + data)
current_hour = hour_format(time_st);
client.send(current_hour)
client.close()
The client side is on an Ubuntu Azure VM that tries to connect to the Ubuntu VM but no luck:
def get_time():
ip_time_server = '200.68.142.31'
port_time_server = 8080
time_server = (ip_time_server, port_time_server)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client.connect(time_server)
string_time = "GetTime"
client.sendto(socket.gethostbyname(socket.gethostname()).encode(), time_server)
time_response = client.recv(4096)
except socket.error:
client.close()
return "error"
return time_response
This just stays waiting until it times out I tried using port forwarding but doesn´t seem to do anything. I disabled the firewall on both host Windows machine and the guest Ubuntu Virtualbox but nothing. What am I doing wrong?