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.
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.
Doing SSH from the host machine to Linux Virtual machine will work great!!
Related
I want to do a connection between a computer simulating being a server and another computer being a user, both with Linux.
In the first computer I've created a directory called "server" and in that directory I've done the following command:
python3 -m http.server 8080
Then I can see that directory going to the localhost. But what I want is to see that localhost from the other computer, I tried with wget, and the gnome system of sharing files but none of them worked, and I'm not seeing any solution online.
I'm not sure I fully understand your question but if you want to reach your folder from an other computer with your command python3, you can use the option -b followed by an IP address used on your linux.
All you need to do is get the IP of the server using ifconfig command.
ifconfig | grep 192 make sure not to use the broadcast address part.
Now logon to the other machine and hit the command
http://192.168.71.145:8080
And it should work.
Here I have assumed that your IP is 192.168.71.145 and the port is 8080.
Just change the IP and port as per your values.
If I'm understanding your question correctly you want to connect to the server from another machine on the same network.
If so you can run hostname -I on the server to output to the local IP address of the server, you can then use this on the other machine to connect to it (provided they are on the same network)
I wonder and i've been trying everything to get my program with python sockets to work remotely. When I say remotely is like, I run the server in my computer and my friend at his house can run the client and connect to my server. Is this possible without using Hamachi? Pls let me know, because I'm already dying by trying so many things and installing and uninstalling programs.
You have to activate port forwarding on your router so that everything that comes on the specific port is forwarded to your local IP (and the port should be open).
I coded up the simple server and client on this page:
https://wiki.python.org/moin/TcpCommunication
In the code the port 5005 is specified, but when I run them, the server reports that other ports were used (e.g. 5807, 5810). Why is this?
(I'm running Anaconda python 2.7.8 through pycharm on Windows 7).
Different ports, because this Source port for client and it's taken randomly.
Target Server Socket 5005, must working fine.
I am trying to send a string from the windows to the linux vmware on the same machine.
I did the following:
- opened a socket on 127.0.0.1 port 50000 on the linux machine and reading the socket in a while loop. My programming language is python 2.7
- send a command using nc ( netcat ) on 127.0.0.1 port 50000 from the windows machine ( using cygwin ).
However, I dont receive any command on the linux machine although the command sent through windows /cygwin is successful.
I am using NAT ( sharing the hosts IP address ) on the VMWARE Machine.
Where could be the problem?
When you use NAT, the host machine has no way to directly contact the client machine. All you can do is usign port forwarding to tell vmware that all traffic directed to the designated ports on the host is to be delivered to the client. It is intended to install a server on the client machine that can be accessed from outside the host machine.
If you want to test network operation between the host and the client, you should configure a host-only adapter on the client machine. It is a virtual network between the host and the client(s) machine(s) (more than one client can share same host-only network, of course with different addresses)
I generally configure 2 network adapters on my client machines :
one NAT to give the client machine an access to the open world
on host-only to have a private network between host and clients and allow them to communicate with any protocol on any port
You can also use a bridged interface on the client. In this mode, the client machine has an address on same network than the external network of the host : it combines both previous modes
Your problem is multi-fold
1st
setup Ubuntu-VM's IP-network & a static IP-address of this guest O/S.
VALIDATE:
$> ifconfig // list all setup Ubuntu interfaces/addresses
2nd
if your VM guest is hosted as being connected to a different IP-network, than your Windows system, make sure there is a connectivity and route between these two hosts ( VMnet configurator in VmWare will help a lot to solve this ).
VALIDATE:
C:\ ping <aUbuntuVmIpADDRESS> // prove an online visibility Win->UbuntuVM
3rd
make sure your Windows O/S permits the use your selected TCP-port#
VALIDATE:
list all allowed / add if-needed TCP-port# in Windows Firewall setup
4th
make sure your python sends all socket-traffic not to a Windows local loopback interface <127.0.0.1>, but towards the visible IP-address of the Ubuntu-VM guest O/S, ( setup as per step-1, verified as per step-2 ) using an unused, permitted TCP-port# ( verified/setup as per step-3 )
I'm have an issue with running the built in Python server that comes with 3.1, this may or may not be an issue with Python, in fact it probably isn't.
I start my server in the correct directory with "python -m http.server 8000" as the documentation suggests (http://docs.python.org/release/3.1.3/library/http.server.html).
When I navigate to that port on my local network with another computer using the url 192.168.2.104:8000 (my local ip and the port) my page loads. When I use my global IP, however, it stops working. Port 8000 is forwarded correctly. I used www.yougetsignal.com to verify that port 8000 was open using my global IP. Why in the world would Chrome be saying "Oops! Google Chrome could not connect to [REDACTED]:8000" then? Other server applications (such as my Minecraft server) work just fine. Is there something I'm missing? Furthermore, why would yougetsignal connect to my port but not Chrome?
With most routers ports are only mapped when someone connects from the outside (internet/WAN). You're testing it from your LAN so basically you're connecting to your router when you use your public IP. Ask a friend to test, i.e. from an outside connection.