Question

In this lab you will write a simple chat application in Python using TCP sockets. The...

In this lab you will write a simple chat application in Python using TCP sockets. The chat application consists of a chat server and a chat client. At any one time, the chat server is communicating with just one chat client. When the client and the server are done chatting, they exchange end messages which ends the session. The client and server read and write Unicode strings using the readUTF() and writeUTF() methods of DataInputStream and DataOutputStream respectively. After compilation, start the Chat server and then the Chat client in two separate command windows on the localhost. Let the client and server exchange a couple of messages from their respective windows and then end the session by exchanging the end message. 4.1 Provide your server and client code as well as the message exchanges (screenshots of server and client command windows) to Blackboard.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. Python Socket Server:
    import socket
    serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serv.bind(('0.0.0.0', 8080))
    serv.listen(5)
    while True:
    conn, addr = serv.accept()
    from1 = ''
    while True:
    data = conn.recv(4096)
    if not data: break
    from1 += data
    print (from1)
    conn.send("I am SERVER\n")
    conn.close()
    print ('client disconnected')
      

  2. Python Socket Client:

    import socket
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = ('', 6166)
    client.connect(host)
    client.send("I am CLIENT\n")
    from_server = client.recv(4096)
    client.close()
    print (from_server)

we open to command prompts one for client and another for server run at a time.

Add a comment
Know the answer?
Add Answer to:
In this lab you will write a simple chat application in Python using TCP sockets. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT