Question

Use Python TCP socket to implement an application with client-server architecture. In this application, client must...

Use Python TCP socket to implement an application with client-server architecture. In this application, client must read a line of characters from its input and send it to the server. The server must remove all non-alphanumeric characters from the input and send the modified data to the client. The client must receive the modified data and displays it on its screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Plese find below the code,

# save the below code as server.py

import socket

def remove_non_alphanumeric_characters(msg):
    """
    function to remove the nin alphanumeric chars from cleient message
    """
    return "".join([x for x in msg if x.isalnum()])
s = socket.socket()
port = 30013 #port number for connecting to server
host = socket.gethostname() # default localhost
s.bind((host, port)) # binding host with port
s.listen(5) # listening the client to connect
print("server listening.........\n")
while True:
   client, address = s.accept()
   client_msg = str(client.recv(1024).decode())
   print("Message received from client : ", client_msg)
   # removing the special character and sending to client
   client.send(remove_non_alphanumeric_characters(client_msg).encode())
   client.close()

# save the below code as client.py

import socket
# """ socket object """
s = socket.socket()
# port number for connection
port = 30013
host = socket.gethostname() # default hostname
s.connect((host, port)) # getting connection from host
msg = input("Enter the message  : ")
s.send(msg.encode()) # message sent to server
filtered_message  = s.recv(1024).decode()
print("Message after removing the non-alphanumeric charcaters : ",filtered_message)
s.close() # closing the connection

#first run the server.py and in another terminal/console run the client.py

#output

➜ python server.py
server listening.........

Message received from client : this_is_#message!
Message received from client : this_is@@@another.msg$#

➜ python client.py
Enter the message : this_is_#message!   
Message after removing the non-alphanumeric charcaters : thisismessage


➜ python client.py
Enter the message : this_is@@@another.msg$#
Message after removing the non-alphanumeric charcaters : thisisanothermsg

Add a comment
Know the answer?
Add Answer to:
Use Python TCP socket to implement an application with client-server architecture. In this application, client must...
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
  • Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or...

    Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or UDP Protocol, the application should do the following: 1. Client reads a line of characters (data) from its keyboard and sends data to server 2. Server receives the data and converts characters to uppercase 3. Server sends modified data to client 4. Client receives modified data and displays line on its screen

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • I'm busy experimenting with TCP socket connnections. I have made a client SOCK_STREAM socket andi've got...

    I'm busy experimenting with TCP socket connnections. I have made a client SOCK_STREAM socket andi've got a few questions: + Is there any way that a streaming(TCP) socket can get data from another socket without having to connect to it? + Is it safer to have a socket that a client connects to send data, and another one that the client gets data from (the server sockets exchange data) instead of one up and down socket? Because what i'm trying...

  • To develop a client/server application using TCP sockets and the C programming language that is capable...

    To develop a client/server application using TCP sockets and the C programming language that is capable of supporting multiple concurrent service requests from different clients. PROBLEM You are to use the Ubuntu operating system as well as both the client and the server programs. You are to modify your server program to process requests from more than one client concurrently. This means different clients may request either the same service or a total different one. The services supported by your...

  • I need some help in creating a pair of programs in Python UDPClient and UDPServer, that...

    I need some help in creating a pair of programs in Python UDPClient and UDPServer, that use the UDP protocol to communicate with each other. Once the sockets are set up, the communication will go as follows: The client reads a line of characters (data) from its keyboard and sends the data to the server. The server receives the data and converts the characters to uppercase. The server sends the modified data to the client. The client receives the modified...

  • In this assignment, you design a simple chat room in the form of a network application which uses the services of a TCP/IP computer network. Your design should have a clientserver architecture in whic...

    In this assignment, you design a simple chat room in the form of a network application which uses the services of a TCP/IP computer network. Your design should have a clientserver architecture in which the server is multi-threaded. Then, you need to implement the server-side of the chat-room application in Java (implementing the client-side is optional). The server maintains a list (an ArrayList will work well) of all the active connections. It will listen on a port for a new...

  • implement the follwing code using command promp or Eclipse or any other program you are familiar with. keep the name of...

    implement the follwing code using command promp or Eclipse or any other program you are familiar with. keep the name of the classes exatcly the same as requested for testing purpose. please follow each instruction provided below Objective of this assignment o get you famililar with developing and implementing TCP or UDP sockets. What you need to do: I. Implement a simple TCP Client-Server application 2. and analyze round trip time measurements for each of the above applications 3. The...

  • 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,...

  • Assignment One program will be the update server and the other will be the update client....

    Assignment One program will be the update server and the other will be the update client. Here is how the two programs should interact with each other: Server 1. the server starts up and reads the version number in the data.bin file and stores it in memory. 2. The server binds to a port and awaits connections. Client 1. The client starts up and it will first read the version number found within it's own data.bin file. 2. The client...

  • The following must be coded using Python programming language: In this assignment you will implement two...

    The following must be coded using Python programming language: In this assignment you will implement two programs: a chat client and a server. The server will listen to a known port for new connections from clients. When a client connects, it will be able to authenticate with the server and then join a chat room and send messages.

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