i can't figure out how to send a message from client (on the main machine, windows 10) to the server (ubuntu on VM). Here's my client code on windows 10:
import socket
target_host = "10.0.2.15" target_port = 1236
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((target_host, target_port))
client.send("ABCDEF")
response = client.recv(1024)
print(response)
And here's the server code on the VM:
import socket
import threading
bind_ip: "10.0.2.15"
bind_port: 1236
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind((bind_ip, bind_port))
server.listen(5)
print("Listening on %s:%d"%(bind_ip, bind_port))
def handle_client(client_socket):
request = client_socket.recv(1024)
print("Recived: %s"%request)
client_socket.send("Recived!")
client_socket.close()
while True:
client, addr = server.accept()
print("Accepted connection from %s:%d"%(addr[0],addr[1]))
client_handler = threading.Thread(target=handle_client, args=(client,))
client_handler.start()
If i run both the client and the server con the same machine it works fine, but if i run the server on the VM and the client on the main machine it doesn't work.