Skip to content

Commit

Permalink
First working version of project
Browse files Browse the repository at this point in the history
  • Loading branch information
anadepaula committed Apr 3, 2020
0 parents commit 3f23a31
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
.vscode/*
__pycache__/*
.python-version
6 changes: 6 additions & 0 deletions CHANGELOG
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)
20 changes: 20 additions & 0 deletions README
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!
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1
Empty file added __init__.py
Empty file.
25 changes: 25 additions & 0 deletions client.py
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}')
5 changes: 5 additions & 0 deletions localenv
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:
4 changes: 4 additions & 0 deletions message_wrapper.py
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
3 changes: 3 additions & 0 deletions requirements.txt
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
25 changes: 25 additions & 0 deletions server.py
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)
7 changes: 7 additions & 0 deletions settings.py
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')

0 comments on commit 3f23a31

Please sign in to comment.