diff --git a/Async_socket_read_and_write/Sender.py b/Async_socket_read_and_write/Sender.py new file mode 100755 index 0000000..6e89c14 --- /dev/null +++ b/Async_socket_read_and_write/Sender.py @@ -0,0 +1,53 @@ +import socket +import threading +import ctypes +import time +import subprocess +import os +print(os.getpid()) + +IPV6=subprocess.getoutput("curl -6 icanhazip.com").split()[-1] + + +soc=socket.socket(socket.AF_INET6,socket.SOCK_DGRAM) +soc.bind((IPV6,6969)) +soc.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) +soc.settimeout(0.1) + +flag=[False] # Item to be sent ready +flag_id=id(flag) + +def serve(): + global flag + try: + while True: + assert flag!=[None] + try: + if(flag==[False]): + data,addr=soc.recvfrom(1024) + print(data) + except: + pass + + except AssertionError: + pass + + +thread=threading.Thread(target=serve) +thread.start() + + +while True: + try: + if(flag==[False]): + flag[0]=True + soc.sendto(b"Data",(IPV6,8080)) + flag[0]=False + time.sleep(0.1) + except: + print("INTERRUPT") + flag[0]=None + break + + + diff --git a/Async_socket_read_and_write/display.py b/Async_socket_read_and_write/display.py new file mode 100755 index 0000000..2e52319 --- /dev/null +++ b/Async_socket_read_and_write/display.py @@ -0,0 +1,16 @@ +import socket +import subprocess + +IPV6=subprocess.getoutput("curl -6 icanhazip.com").split()[-1] + +soc=socket.socket(socket.AF_INET6,socket.SOCK_DGRAM) +soc.bind((IPV6,8080)) +count=0 +while True: + try: + data,addr=soc.recvfrom(1024) + count+=1 + print(data.decode(),addr,count,sep="\t",end="\r") + except Exception as e: + print(e) + break diff --git a/Async_socket_read_and_write/prompter.py b/Async_socket_read_and_write/prompter.py new file mode 100755 index 0000000..39fe8a2 --- /dev/null +++ b/Async_socket_read_and_write/prompter.py @@ -0,0 +1,14 @@ +import socket +import subprocess + + +IPV6=subprocess.getoutput("curl -6 icanhazip.com").split()[-1] + +soc=socket.socket(socket.AF_INET6,socket.SOCK_DGRAM) + +while True: + try: + input("SEnd prompt : ") + soc.sendto(b"PROMPT",(IPV6,6969)) + except: + break \ No newline at end of file