I want to connect with TCP/IP communication between virtual box and my own machine. My machine is ubuntu and virtual machine win8
I created slave ubuntu side like this: TCP_IP address refer to my win 8 ipv4 address
TCP_IP = '10.0.2.2'
TCP_PORT = 502
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((TCP_IP, TCP_PORT))
at the win 8 side, i am using Simply Modbus Tcp Program and i gave the that ip addres my ubuntu side's ethernet ip address ( i find with ifconfig)192.168.... but connection cant start.
I have this error my windows side:
Error 63: occured at TCP Open Connection
The network connection was refused by the server
Judging from the error message, the server is either not listening on port 502, or there is a firewall rule that blocks that port.
Related
I'm implementing a simple DNS server, which I want to run on my pc. But, as far as I understand the combination of my IP and port 53 (standard DNS server port) is already occupied.
This is how I tried to open socket:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 53))
This is an error message I get:
socket.error: [Errno 98] Address already in use
But, when I use 127.0.0.1 as IP address when creating a socket, everything works fine and I'm able to get requests.
This is what have tried so far (in Linux terminal I tried to kill the socket):
fuser -k -n udp 53
But it didn't work. So how can I run DNS server on my own IP address?
I create a simple python server:
import socket
server=socket.socket()
server.bind(("0.0.0.0",8820))
server.listen(1)
(client_socket,client_address)=server.accept()
client_name=client_socket.recv(1024)
client_socket.send("Hello "+client_name)
client_socket.close()
server.close()
when I run this script in a VPS I cannot connect to this server
why?
(I get the IP address of the server( with ifconfig command on bash console) and when I run a client script that connect to this address it doesn't connect)
Try to bind the socket server to the vps public IP address and try to avoid ports bellow 10,000 I think most of firewalls prevent incoming connections through ports under 10,000.
I am trying to make a simple and very low level UDP server on Cloud9.
What I would like to do is to open an UDP socket on some port and some ip so that it is accessible from the extern and so that I can get an incoming UDP packet.
I tried to do something like
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", 12345))
But then I wouldn't know the ip. I naively tried to do an ifconfig but I got an ip that I couldn't even ping.
I found out about the IP and PORT environment variables, but IP is always 0.0.0.0.
Is there any way to do what I need?
Sorry to disappoint you, but that is not possible. At this moment only TCP port 8080 in the workspace can be accessed from the internet. So you can develop the UDP server and test its functionality from the same workspace, but to make it work from external sources you should deploy the code to a hosting provider.
I have a ZMQ server listening on port 12345 TCP. When another server connects on that port locally or via VM it works fine, but if I try from a remote server that has to go through port forwarding on my Fios firewall it just bombs. The packets are showing up in Wireshark but ZMQ just ignores them. Is there anyway to get past this?
You shouldn't be able to bind more than once to the same port number, either from the same process or another.
ZMQ should give a failure when you issue bind with a port number already in use. Are you checking return codes?
This is a newbie question for TCP-based communication in Python. I am trying to establish a TCP-based communication between two *NIX systems via an SSH tunnel and the Python socket module. I have used the two first examples "echo server" and "echo client" from this Python MOTW website: http://www.doughellmann.com/PyMOTW/socket/tcp.html.
The communication worked fine on the same *NIX system (HOST1) but failed over the ssh tunnel.
I logged into the second *NIX system with ssh -L 10000:HOST2:10000 USERNAME#HOST2. Then I played around and tried to establish the communication in the same manner by starting the python script for the server on HOST2 and the script for the client on HOST1. This I got on stderr:
python test_socket_client.py
connecting to localhost port 10000
Traceback (most recent call last):
File "test_socket_client.py", line 10, in <module>
sock.connect(server_address)
File "<string>", line 1, in connect
socket.error: [Errno 111] Connection refused
When I started server and client vice versa on HOST1 and HOST2, respectively, I got the same message.
What am I doing wrong?
Your server binds its socket to localhost:10000 -- which means it listens to connections from the loopback interface only. The SSH command line instructs SSH to tunnel local connections to port 10000 to connections to HOST2:10000. Your client Python program connects to localhost:10000, and the remote end of the SSH link then tries to connect to HOST2:10000. Even though that's the same port and the same machine as your socket is bound to, it's a different interface, to which your socket is not listening.
Change the SSH command line to ssh -L 10000:localhost:10000 USERNAME#HOST2, or bind your server's listening socket to all interfaces: server_address = ('', 10000). The empty string serves as INADDR_ANY.
Of course, what Gary van der Merwe said is true: SSH would need to be running at the time you run your client Python program on HOST1.
I would check that your server is listening on the server host, and that the ssh client is listening on the client host. You can run netstat -tnlp to check this.
Are you sure that your ssh client is still open when you are running your client. You either need to run shh in one terminal, and your client in another, or run ssh -Nf which causes ssh to go to the background after it has authenticated.