Last active
November 30, 2020 19:29
-
-
Save 1ycx/f65a11ace7975990965343d0a92f17b1 to your computer and use it in GitHub Desktop.
Revisions
-
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ try: print("Data : ", message.decode()) print("Address : ", address) s.sendto(data.encode(), ('<broadcast>', server_port)) except (KeyboardInterrupt, SystemExit): exit() @@ -45,7 +45,7 @@ s.bind((host, port)) data = "Secret key : s76fshg23" try: s.sendto(data.encode(), ('<broadcast>', server_port)) message, address = s.recvfrom(8192) print("Got data, addr from server - ") @@ -68,7 +68,7 @@ except (KeyboardInterrupt, SystemExit): import socket import time sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', 0)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) while True: -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Run server and client in seperate terminals. Server first then client. ### `Server.py` ```python3 import socket @@ -29,7 +29,7 @@ except (KeyboardInterrupt, SystemExit): exit() ``` ### `Client.py` ```python3 import socket -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,16 +68,17 @@ except (KeyboardInterrupt, SystemExit): import socket import time sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(("localhost", 0)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) while True: data = '{0}\n'.format(time.strftime("%H:%M:%S", time.localtime())) sock.sendto(data.encode(), ('<broadcast>', 5566)) time.sleep(5) ``` *Client* : ```bash $ nc -k -w 1 -ul 5566 22:45:45 22:45:50 ``` -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ sock.bind(('',0)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) while True: m = '{0}\n'.format(time.time()) sock.sendto(m,("<broadcast>",5566)) time.sleep(5) ``` *Client* : -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Docs : Run server and client in seperate terminals. Server first then client. @@ -58,7 +58,7 @@ except (KeyboardInterrupt, SystemExit): ``` ## Notes : - Check out this interesting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html - Another way to broadcast (run in two terminals) : -
1ycx revised this gist
Feb 10, 2019 . 3 changed files with 58 additions and 48 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,62 @@ Run server and client in seperate terminals. Server first then client. ## `Server.py` ```python3 import socket host = '' port = 51424 server_port = 51423 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind((host, port)) data = "Secret key : s76fshg23" try: message, address = s.recvfrom(8192) print("Got data, addr from client - ") print("Data : ", message.decode()) print("Address : ", address) s.sendto(data.encode(), ("<broadcast>", server_port)) except (KeyboardInterrupt, SystemExit): exit() ``` ## `Client.py` ```python3 import socket host = '' port = 51424 server_port = 51423 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind((host, port)) data = "Secret key : s76fshg23" try: s.sendto(data.encode(), ("<broadcast>", server_port)) message, address = s.recvfrom(8192) print("Got data, addr from server - ") print("Data : ", message.decode()) print("Address : ", address) except (KeyboardInterrupt, SystemExit): exit() ``` **Notes** - Check out this interesting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html @@ -22,5 +78,6 @@ while True: *Client* : ```bash $ nc -k -w 1 -ul 5566 22:45:58 22:45:58 ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +0,0 @@ -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Run server and client in seperate terminals. Server first then client. - Check out this interesting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html - Another way to broadcast (run in two terminals) : *Server* : ```python3 import socket -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 21 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,24 @@ Run server and client in seperate terminals. Server first then client. **Notes** - Check out this interesting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html - Another way to broadcast (run in two terminals) : *Server* : ```python3 import socket import time sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('',0)) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) while True: m = '{0}\n'.format(time.time()) sock.sendto(m,('<broadcast>',5566)) time.sleep(5) ``` *Client* : ```bash $ nc -k -w 1 -ul 5566 1431473025.72 ``` -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@ Run server and client in seperate terminals. Server first then client. Notes - Check out this interesting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html -
1ycx revised this gist
Feb 10, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Docs Run server and client in seperate terminals. Server first then client. Notes - Check out this intresting pythonsheet on **`Socket`** : https://www.pythonsheets.com/notes/python-socket.html -
1ycx revised this gist
Feb 10, 2019 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ import socket host = "127.0.0.1" port = 51424 server_port = 51423 @@ -12,7 +12,7 @@ data = "Secret key : s76fshg23" try: s.sendto(data.encode(), (host, server_port)) message, address = s.recvfrom(8192) print("Got data, addr from server - ") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ import socket host = "127.0.0.1" port = 51423 client_port = 51424 @@ -18,6 +18,6 @@ print("Address : ", address) # Acknowledge it. s.sendto(data.encode(), (host, client_port)) except (KeyboardInterrupt, SystemExit): exit() -
1ycx created this gist
Feb 10, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # Docs Run server and client in seperate terminals. Server first then client. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import socket host = '' port = 51424 server_port = 51423 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind((host, port)) data = "Secret key : s76fshg23" try: s.sendto(data.encode(), ('<broadcast>', server_port)) message, address = s.recvfrom(8192) print("Got data, addr from server - ") print("Data : ", message.decode()) print("Address : ", address) # Acknowledge it. except (KeyboardInterrupt, SystemExit): exit() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import socket host = '' port = 51423 client_port = 51424 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind((host, port)) data = "Secret key : 6sc45hj90" try: message, address = s.recvfrom(8192) print("Got data, addr from client - ") print("Data : ", message.decode()) print("Address : ", address) # Acknowledge it. s.sendto(data.encode(), ('<broadcast>', client_port)) except (KeyboardInterrupt, SystemExit): exit()