Skip to content

Commit

Permalink
more work done
Browse files Browse the repository at this point in the history
  • Loading branch information
arodrigoca committed Oct 24, 2017
1 parent 79b3174 commit c19a9ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 13 additions & 8 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
import socket
import sys

def sendRegister(server, port, sipmsg, my_socket, myaddr):

def doClient(server, port, line):
finalMsg = sipmsg + " " + "sip:" + myaddr + " " + "SIP/2.0\r\n\r\n"
# print("Enviando:", finalMsg)
my_socket.send(bytes(finalMsg, 'utf-8'))
data = my_socket.recv(1024)
print('Received: ', data.decode('utf-8'))


def doClient(server, port, sipmsg, myaddr):

with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as my_socket:
try:
Expand All @@ -17,11 +25,7 @@ def doClient(server, port, line):
except socket.gaierror:
sys.exit('Incorrect or not found server tuple')

print("Enviando:", line)
my_socket.send(bytes(line, 'utf-8') + b'\r\n')
data = my_socket.recv(1024)
print('Recibido -- ', data.decode('utf-8'))

sendRegister(server, port, sipmsg, my_socket, myaddr)
print("Socket terminado.")


Expand All @@ -30,9 +34,10 @@ def doClient(server, port, line):
try:
SERVER = sys.argv[1]
PORT = int(sys.argv[2])
LINE = ' '.join(sys.argv[3:])
SIPMSG = sys.argv[3]
MYADDR = ' '.join(sys.argv[4:])

except(FileNotFoundError, IndexError):
sys.exit('Usage: IP_ADDRESS PORT, STRING')

doClient(SERVER, PORT, LINE)
doClient(SERVER, PORT, SIPMSG, MYADDR)
9 changes: 7 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class SIPRegisterHandler(socketserver.DatagramRequestHandler):
Echo server class
"""

usersList = []

def handle(self):
"""
handle method of the server class
Expand All @@ -20,9 +22,12 @@ def handle(self):

print("Incoming client message from: ")
print(self.client_address)
self.wfile.write(b"Hemos recibido tu peticion")
self.wfile.write(b"SIP/2.0 200 OK\r\n\r\n")
for line in self.rfile:
print("El cliente nos manda: ", line.decode('utf-8'))
stringMsg = line.decode('utf-8')
print("Client sent: ", stringMsg)
addrIndx = stringMsg.find(":")
break

if __name__ == "__main__":
# Listens at localhost ('') port 6001
Expand Down

0 comments on commit c19a9ba

Please sign in to comment.