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]".
but nothing is replaying when i client send a string for the listener on port 5009
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]".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
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() |
anyone can help?