# TCP Server Code host="127.0.0.1" # Set the server address to variable host port=4446 # Sets the variable port to 4444 from socket import * # Imports socket module s=socket(AF_INET, SOCK_STREAM) s.bind((host,port)) # Binds the socket. Note that the input to # the bind function is a tuple s.listen(1) # Sets socket to listening state with a queue # of 1 connection print "Listening for connections.. " q,addr=s.accept() # Accepts incoming request from client and returns # socket and address to variables q and addr data=raw_input("Enter data to be send: ") # Data to be send is stored in variable data from # user q.send(data) # Sends data to client s.close() # End of code
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question