Gie Grajo
Gie Grajo

Reputation: 197

How to connect Linux Virtual Machine from its host computer?

I'm creating a simple chat app using Python.

The server code is in the Linux VM (I am using Virtual Box), and the client code is in the Windows 10 computer where the Virtual Box is installed.

I'm trying to connect it with the Python socket.

It works when I ping both machines to each other.

My problem is what port should I put in the client code:

Client

import socket
import subprocess

cliente = socket.socket()

try:
    cliente.connect(('192.168.1.33',9090))
    cliente.send("1")

I tried every port available; however, nothing works. I think I am missing something to make this work.

Upvotes: -1

Views: 1040

Answers (2)

Biku Shah
Biku Shah

Reputation: 117

Doing SSH from the host machine to Linux Virtual machine will work great!!

Upvotes: 0

Mohammed Osama
Mohammed Osama

Reputation: 125

First, You need to make sure that the port number passed to bind function in server code in Linux VM is the same port number used by connect function in your client.

Check this simple server-client example in python which is using port 12345 : https://www.tutorialspoint.com/python/python_networking.htm

Second, (based on your comments) the IP address that should be used in client connect function is the IP address of the machine running the server code which is in your case the Linux VM. Try to run the shell command ifconfig in the Linux VM to get the IP address.

If this address didn't work you can change the network settings of the virtual machine to bridged instead of NAT and try again the ifconfig command and get the new IP address.

Upvotes: 1

Related Questions