I am trying to connect to a client computer in order to send integer values using UDP from my server computer. The problem arises (I believe) due to the server computer sending and listening to UDP communication in Python, while the client receives and sends messages from a MATLAB script. Theoretically this arrangement should not matter since the UDP communication should not be affected by the coding language at all.
Server-side code (Python):
import socket
commandVal = 0 #Message to be sent
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(np.uint8(commandVal), (hostIP, portNum)) #hostIP and portNum are defined separately
sock.connect((hostIP, portNum))
while True:
data, addr = sock.recvfrom(1024)
print("received message: %s" % data)
Client-side code (MATLAB):
packetlength = 50
waitdur = 15000
mssgA = judp('receive',port,packetlength,waitdur);
if mssgA(1) == 0
judp('send',port, host,int8('error'))
else
judp('send',port, host,int8('success'))
I know the ports and IP addresses are defined correctly, because I can send and receive messages if I use the MATLAB-based judp function to communicate from the server end.
When the Python code is used, the message is sent to the client, but no 'error' or 'success' message is received in return. What is the issue here?
I have tried changing firewall settings, and going through the documentation for both judp and socket. I haven't found a solution yet.
I am a bit confused as to who is the client and who is the server in your code. It appears your "server" is sending commands/requests to the "client", which seems backwards?
That being said, I think your main issue comes from the fact that you're never binding your "server" socket to a particular address, which means that your "client"'s messages are not recognized as being addressed to the "server".
Also, you're using the same port for sending and receiving in your MATLAB script, this could be a typo, or it could be intended, I'm afraid I can't say without more information on the rest of your code.
server.py
client.m