user123959
user123959

Reputation: 1256

Python UDP and TCP communication between VMware host and guest not working

I am using VMWare workstation with a Windows 7 host and a Ubuntu guest. I am trying to have communication between the two with either UDP or TCP--have not had success with either. I have my VM set to Bridged networking mode which gives it its own IP address. I have the most basic TCP/UDP server and client code from any example site online which I've tested and works fine If I run both on the host machine. However, when I have either the client or the server on the VM, the communication does not go through.

To try and figure out what's going on, I ran the UDP server on the host machine and ran Wireshark on the host with it filtered to UDP; then I tried sending a packet from the client on the guest, and in wireshark I can see the the packet is going through but the server just does not seem to want to receive it. Any ideas?

UDP Server:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind the socket to the port
server_address = ('0.0.0.0', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)

while True:
    print >>sys.stderr, '\nwaiting to receive message'
    data, address = sock.recvfrom(4096)

    print >>sys.stderr, 'received %s bytes from %s' % (len(data), address)
    print >>sys.stderr, data

    if data:
        sent = sock.sendto(data, address)
        print >>sys.stderr, 'sent %s bytes back to %s' % (sent, address)

UDP Client:

import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('192.168.100.38', 10000)
message = 'This is the message.  It will be repeated.'

try:

    # Send data
    print >>sys.stderr, 'sending "%s"' % message
    sent = sock.sendto(message, server_address)

    # Receive response
    print >>sys.stderr, 'waiting to receive'
    data, server = sock.recvfrom(4096)
    print >>sys.stderr, 'received "%s"' % data

finally:
    print >>sys.stderr, 'closing socket'
    sock.close()

In wireshark I can see the packet that is sent from the VM client:

Src=192.168.100.42 Dst=192.168.100.38 Proto=UDP

Upvotes: 2

Views: 3389

Answers (1)

nissefors
nissefors

Reputation: 440

server_address = ('127.0.0.1', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)

you tell the socket to listen on packets addressed to 127.0.0.1:10000 but the incoming packages goes to 192.168.100.37:10000. Try

bind(('0.0.0.0', 10000)

Upvotes: 3

Related Questions