Professional Documents
Culture Documents
PA3 Blombach Orduna Stephens Terrill
PA3 Blombach Orduna Stephens Terrill
Team Members:
Name Role
Pseudocode
Roger Chicas-Terrill
Server
- Create socket
- Loop
- Accept connections
- Message that connection is set and ask for name
- Create a thread
- Assign thread to each conversation
- while message is not bye, check messenger
- broadcast message of status
- else
- show user has left message
- once done close the server connection
Client
- setup sockets
- setup threads
- constantly ask for input
- send message
- receive message from server
Carlos Orduna
Server
Create socket
Assign IP and port to socket
Socket listener for client input
While no Bye msg
receive address
verify who sent message
receive client response
forward response
loop while
disconnect session
close socket
Client
Server:
create a server socket
create a thread
receive connections loop:
for each connection:
create new thread
while message != 'bye':
receive message
broadcast message
disconnect session
close socket
Client:
create a socket and initialize variables
create a thread for message reception
while message != 'bye':
read keyboard input
send to server
print response
close socket
George Blombach
Server
Client
Sockets are created using socket(AF_INET, SOCK_STREAM). The first parameter indicates
the network is using IPv4. The second parameter indicates the socket type, specifically, a
TCP socket is being used in this case. Note that in order for data to be exchanged between
a client and a server using a TCP socket, a connection must first be established.
The server dictates where the clients need to connect (in our case localhost). The server
listens on a specific port for clients to connect to. Upon connection, the server assigns a
socket to the client's address and once the client disconnects, the socket is closed.
Testing
Test Plan
a. Alice first establishes TCP connects with server, Alice sends first message
b. Alice first establishes TCP connects with server, Bob sends first message
c. Bob first establishes TCP connects with server, Alice sends first message
d. Bob first establishes TCP connects with server, Bob sends first message
NOTE: We implemented a sequential assignment of X and Y to the first and second connected
clients, respectively, so the test plan differs slightly from the assignment instructions. However,
our software design and testing will still show that the connection sequence of the clients is
detached from the sending and receiving of messages from those clients.
Test Results
Testing was performed by each of the team members. The results of each test was consistent
with the Results screenshots included herein.
The program design using sockets and thread ensured that the connection of the client was
detached from the randomness of message communication between clients.
Initial testing revealed a difference in code requirements for Python 3, which was the team’s
development platform, and Python 2, which was available in the Mininet virtual machine. The
code was adjusted to accommodate the Mininet environment, both versions of the code are
provided below.
All test results were conclusive and representative of the project goals and expectations.
Interesting Findings
1. The global checkPoint (Bool) variable had to be declared in the While loop within the
function, but the other global variable for clients (OrderedDict) did not have be declared
2. Our initial code was written in Python 3, because this is an industry standard and Python
2 is End of Life. However, we encountered issues with syntax difference between the
two platforms and during code review and testing we needed to adjust some of the code.
Both versions of the code have been submitted in this assignment.
a. client.send(bytes('You are connected to chat. Type "bye" to quit.',encoding)) →
client.send(bytes('Connected to chat server. Enter your name and press
enter.').encode(encoding))
b. Input → raw_input
3. We implemented the client X and Y assignment in a way that seemed to make sense to
us, assigning X to the first connection and Y to the second. However, the testing plan
included both a letter identifier and and name identifier. We implemented these both
independently of each other, so the first client connecting wout be X, but the user could
be Alice or Bob or someone else. This altered the test plan slightly from the assignment
description, but it also made the X and Y identifier redunant. In actuallity, there are only
two scenarios that need to be tested:
a. Client 1 connecting first, and Client 1 sending a message after client 2 joins
b. Client 1 connecting first, and Client 2 sending a message after connecting
The other two scenarios are just mirror images of the first two, and are redundant.
Results
Test Plan 1:
Test Plan 2:
Test Plan 3:
Test Plan 4:
Server
Client
Final Code : Python 2 (use with mininet)
Server
# variables
serverName =''
serverPort = 12021
messageSize = 1024
clients = collections.OrderedDict()
encoding ='utf8'
checkPoint = False
order =['X','Y']
while True:
#instantiate global variable
global checkPoint
#get message from client
message = client.recv(messageSize)
#if the message is not a disconnect request
if message !=bytes('bye').encode(encoding):
#check who sent the message first
#only when two people have been connected to the system
if checkPoint == False and len(clients) == 2:
checkPoint = True
statusMessage = '*** ' +
order[list(clients.values()).index(name)] + ': ' +\
name + ' received before ' +
order[(list(clients.values()).index(name) + 1) % len(clients)] +\
': ' + list(clients.values())[
(list(clients.values()).index(name) + 1) % len(clients)] + ' ***'
#send status message to all clients
broadcast(bytes(statusMessage).encode(encoding))
serverSocket.listen(1)
print('waiting for connections')
newThread = Thread(target=acceptConnection)
newThread.start()
newThread.join()
#run main
if __name__ == '__main__':
Main()
Client
# Programming Assignment 3
# Blombach, Chicas-Terrill, Orduna, Stephens
# TCPChatClient.py
# February 18, 2020
# variables
serverName = 'localhost'
serverPort = 12021
messageSize = 1024
encoding ='utf8'