creating tcp servers in python is just as easy as creating client you might want to use your own tcp server when writing command shells or crafting proxy (both of which we'll do laterlet' start by creating standard multi-threaded tcp server crank out the code belowimport socket import threading bind_ip bind_port server socket socket(socket af_inetsocket sock_streamserver bind((bind_ip,bind_port)server listen( print "[*listening on % :% (bind_ip,bind_portthis is our client-handling thread def handle_client(client_socket)print out what the client sends request client_socket recv( print "[*received%srequest send back packet client_socket send("ack!"client_socket close(while trueclient,addr server accept(print "[*accepted connection from% :% (addr[ ],addr[ ]spin up our client thread to handle incoming data client_handler threading thread(target=handle_client,args=(client,)client_handler start(to start offwe pass in the ip address and port we want the server to listen on next we tell the server to start listening with maximum backlog of connections set to we then put the server into its main loopwhere it is waiting for an incoming connection when client connects we receive the client socket into the client variableand the remote connection details into the addr variable we then create new thread object that points to our handle_client functionand we pass it the client socket object as an argument we then start the thread to handle the client connection and our main server loop is ready to handle another incoming connection the handle_client function performs the recv(and then sends simple message back to the client if you use the tcp client that we built earlieryou can send some test packets to the server and you should see output like the following[*listening on : [*accepted connection from : [*receivedabcdef that' itpretty simplebut this is very useful piece of code which we will extend in the next couple of sections when we build netcat replacement and tcp proxy