hello, im trying to make i simple udp server client (two in one).
the client send every 5 second a string to a server(port 23000) and save the respone in "reply = msgFromServer[0]".
in simultane the server wait if a client send a string and reply the "reply = msgFromServer[0]".
anyone can help?
the client send every 5 second a string to a server(port 23000) and save the respone in "reply = msgFromServer[0]".
in simultane the server wait if a client send a string and reply the "reply = msgFromServer[0]".
import binascii import re import socket import sys import logging import os import time from multiprocessing import Process localIP = "0.0.0.0" localPort = 5009 serverAddressPort = ("192.168.0.107", 23000) MESSAGE = "reply1" bufferSize = 108 msgFromServer = "Hello UDP Client" bytesToSend = str.encode(msgFromServer) def start_sender(): global reply UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) while(True): UDPClientSocket.sendto(bytesToSend, serverAddressPort) time.sleep(5) while(True): msgFromServer = UDPClientSocket.recvfrom(bufferSize) reply = msgFromServer[0] def start_listener(): global reply UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) UDPServerSocket.bind((localIP, localPort)) while(True): bytesAddressPair = UDPServerSocket.recvfrom(108) message = bytesAddressPair[0] address = bytesAddressPair[1] UDPServerSocket.sendto(reply, address)#here i reply the bytes from the sender msgFromServer[0] but nothing is sent if __name__ == '__main__': try: p1 = Process(target = start_listener) p1.start() p2 = Process(target = start_sender) p2.start() except Exception as e: print(e) sys.exit()but nothing is replaying when i client send a string for the listener on port 5009
anyone can help?