-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e129706
commit 778b75a
Showing
7 changed files
with
201 additions
and
16 deletions.
There are no files selected for viewing
Binary file not shown.
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,8 @@ | ||
#paint | ||
## Dependencies | ||
|
||
## Running the application | ||
1. Run the server by `python3 server.py IP-ADDR PORT` | ||
2. Run the voice server by `python3 voice_ser.py IP-ADDR PORT1` | ||
3. Run the paint application by `python3 paint.py IP-ADDR PORT` | ||
4. Run the Voice application by `python3 voice_cli.py IP-ADDR PORT1` |
File renamed without changes.
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,74 @@ | ||
|
||
# Python program to implement server side of chat room. | ||
import socket | ||
import select | ||
import sys | ||
from _thread import * | ||
import json | ||
|
||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
|
||
if len(sys.argv) != 3: | ||
print("Correct usage: script, IP address, port number") | ||
exit() | ||
|
||
IP_address = str(sys.argv[1]) | ||
Port = int(sys.argv[2]) | ||
server.bind((IP_address, Port)) | ||
server.listen(100) | ||
|
||
list_of_clients = [] | ||
|
||
def clientthread(conn, addr): | ||
mes= {'type':'message', | ||
'message':'Welcome', | ||
'data':'', | ||
'addr':''} | ||
conn.send(bytes('|'+json.dumps(mes),'utf8')) | ||
while True: | ||
try: | ||
message = conn.recv(2048) | ||
if message: | ||
msg=message.decode() | ||
print(msg) | ||
msg=json.loads(msg) | ||
mes=json.dumps({"type":"draw", "addr":addr[0],"data":msg}) | ||
mes='|'+mes | ||
broadcast(mes, conn) | ||
else: | ||
remove(conn) | ||
|
||
except: | ||
continue | ||
|
||
def broadcast(message, connection): | ||
for clients in list_of_clients: | ||
if clients!=connection: | ||
try: | ||
clients.send(bytes(message,'utf8') ) | ||
except: | ||
clients.close() | ||
|
||
# if the link is broken, we remove the client | ||
remove(clients) | ||
|
||
def remove(connection): | ||
if connection in list_of_clients: | ||
list_of_clients.remove(connection) | ||
|
||
while True: | ||
conn, addr = server.accept() | ||
|
||
"""Maintains a list of clients for ease of broadcasting | ||
a message to all available people in the chatroom""" | ||
list_of_clients.append(conn) | ||
# prints the address of the user that just connected | ||
print(addr[0] + " connected") | ||
|
||
# creates and individual thread for every user | ||
# that connects | ||
start_new_thread(clientthread,(conn,addr)) | ||
|
||
conn.close() | ||
server.close() |
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,53 @@ | ||
import socket | ||
import sys | ||
import time | ||
import select | ||
import pyaudio | ||
from _thread import * | ||
|
||
CHUNK=1024 | ||
FORMAT=pyaudio.paInt16 | ||
CHANNELS=1 | ||
RATE=20000 | ||
|
||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
if len(sys.argv) != 3: | ||
print("Correct usage: script, IP address, port number") | ||
exit() | ||
IP_address = str(sys.argv[1]) | ||
Port = int(sys.argv[2]) | ||
server.connect((IP_address, Port)) | ||
sockets_list = [sys.stdin, server] | ||
|
||
read_sockets,write_socket, error_socket = select.select(sockets_list,[],[]) | ||
server.settimeout(0.035) | ||
|
||
p=pyaudio.PyAudio() | ||
recv_stream=p.open(format=FORMAT,channels=CHANNELS,rate=RATE,output=True,frames_per_buffer=CHUNK) | ||
send_stream=p.open(format=FORMAT,channels=CHANNELS,rate=RATE,input=True,frames_per_buffer=CHUNK) | ||
|
||
def recv_data(): | ||
while True: | ||
try: | ||
for socks in read_sockets: | ||
if socks==server: | ||
data=socks.recv(1024) | ||
recv_stream.write(data) | ||
else: | ||
pass | ||
except: | ||
continue | ||
|
||
def send_data(): | ||
while True: | ||
try: | ||
data = send_stream.read(CHUNK) | ||
server.send(data) | ||
except: | ||
pass | ||
|
||
start_new_thread(recv_data, ()) | ||
start_new_thread(send_data, ()) | ||
|
||
while True: | ||
pass |
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,66 @@ | ||
import socket | ||
import select | ||
import sys | ||
from _thread import * | ||
|
||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
|
||
if len(sys.argv) != 3: | ||
print("Correct usage: script, IP address, port number") | ||
exit() | ||
|
||
IP_address = str(sys.argv[1]) | ||
Port = int(sys.argv[2]) | ||
server.bind((IP_address, Port)) | ||
server.listen(100) | ||
|
||
list_of_clients = [] | ||
|
||
def clientthread(conn, addr): | ||
while True: | ||
try: | ||
message = conn.recv(2048) | ||
if message: | ||
broadcast(message,conn) | ||
else: | ||
remove(conn) | ||
|
||
except: | ||
continue | ||
|
||
|
||
|
||
def broadcast(message, connection): | ||
for clients in list_of_clients: | ||
if clients!=connection: | ||
try: | ||
clients.send(message) | ||
except: | ||
clients.close() | ||
|
||
# if the link is broken, we remove the client | ||
remove(clients) | ||
|
||
|
||
|
||
def remove(connection): | ||
if connection in list_of_clients: | ||
list_of_clients.remove(connection) | ||
|
||
|
||
while True: | ||
conn, addr = server.accept() | ||
|
||
"""Maintains a list of clients for ease of broadcasting | ||
a message to all available people in the chatroom""" | ||
list_of_clients.append(conn) | ||
# prints the address of the user that just connected | ||
print(addr[0] + " connected") | ||
|
||
# creates and individual thread for every user | ||
# that connects | ||
start_new_thread(clientthread,(conn,addr)) | ||
|
||
conn.close() | ||
server.close() |