-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f23a31
Showing
11 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.env | ||
.vscode/* | ||
__pycache__/* | ||
.python-version |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
First working version | ||
|
||
- Added client and server sripts | ||
- Added message wrapper | ||
- Added envvar and settings handling using decouple | ||
- Added git's "boilerplate" (reaadme, changelog, version, gitignore yadda yadda yadda) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Virtual Friendships | ||
|
||
An UDP-based messages service. | ||
|
||
|
||
![beep](https://images.genius.com/271aa1501598f934b3a1cb3084d1e656.900x900x1.jpg) | ||
|
||
🎵 🎵 🎵 | ||
|
||
beep, beep, beep, someone's calling in the computer's network! | ||
beep, beep, beep, I'm speking! You say "beep" and I say "hello!" | ||
|
||
🎵 🎵 🎵 | ||
|
||
# How to | ||
|
||
* Create a virtual environment and install the requirements listed on `requirements.txt`; | ||
* Create a `.env` based on `localenv`; | ||
* Run `server` and `client` scripts at the same time; | ||
* Have fun! |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1 |
Empty file.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import socket | ||
|
||
from message_wrapper import get_message | ||
import settings | ||
|
||
udp_client_socket = socket.socket( | ||
family=socket.AF_INET, | ||
type=socket.SOCK_DGRAM | ||
) | ||
|
||
print('UDP client up and ready to send.') | ||
|
||
|
||
first_message = str.encode('You say: "beep"') | ||
print(first_message) | ||
udp_client_socket.sendto(first_message, settings.SERVER_ADDRESS) | ||
first_response, _ = udp_client_socket.recvfrom(settings.BUFFER_SIZE) | ||
print(first_response) | ||
|
||
while True: | ||
message = get_message(settings.PROMPT) | ||
udp_client_socket.sendto(message, settings.SERVER_ADDRESS) | ||
|
||
response_from_server, _ = udp_client_socket.recvfrom(settings.BUFFER_SIZE) | ||
print(f'Server says: {response_from_server}') |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SERVER_IP=127.0.0.1 | ||
SERVER_PORT=20001 | ||
BUFFER_SIZE=1024 | ||
|
||
PROMPT=You say: |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def get_message(prompt): | ||
message = input(prompt) | ||
encoded_message = str.encode(message) | ||
return encoded_message |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
python-decouple==3.3 | ||
ipdb==0.13.2 | ||
ipython==7.13.0 |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import socket | ||
|
||
from message_wrapper import get_message | ||
import settings | ||
|
||
udp_server_socket = socket.socket( | ||
family=socket.AF_INET, | ||
type=socket.SOCK_DGRAM | ||
) | ||
|
||
udp_server_socket.bind(settings.SERVER_ADDRESS) | ||
print('UDP server up and listening') | ||
|
||
first_message, address = udp_server_socket.recvfrom(settings.BUFFER_SIZE) | ||
print(first_message) | ||
first_response = str.encode('I say: "hello!"') | ||
print(first_response) | ||
udp_server_socket.sendto(first_response, address) | ||
|
||
while(True): | ||
message, address = udp_server_socket.recvfrom(settings.BUFFER_SIZE) | ||
print(f'Client says: {message}') | ||
|
||
response = get_message(settings.PROMPT) | ||
udp_server_socket.sendto(response, address) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from decouple import config | ||
|
||
SERVER_IP = config('SERVER_IP') | ||
SERVER_PORT = config('SERVER_PORT', cast=int) | ||
SERVER_ADDRESS = (SERVER_IP, SERVER_PORT) | ||
BUFFER_SIZE=config('BUFFER_SIZE', cast=int) | ||
PROMPT = config('PROMPT') |