Created
December 31, 2016 09:26
-
-
Save hygull/3d37b73f365788759700a133fd61ed4b to your computer and use it in GitHub Desktop.
To implement a simple TCP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Date of creation : 31 Dec 2016. | |
@Aim of script : To implement a simple TCP server. | |
@Coded by : Rishikesh Agrawani. | |
""" | |
import socket | |
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
host_name = socket.gethostname() #To get the name of host | |
port_number = 1234 | |
print "The name of local machine",host_name #The name of local machine admins-MacBook-Pro-3.local | |
host_port_pair = (host_name,port_number) #A tuple | |
print host_port_pair | |
sock.bind(host_port_pair) #Bind address to the socket | |
sock.listen(10) | |
conn_obj,addr = sock.accept() | |
while True: | |
print "Got a connection from ",addr," => Thanks..." | |
msg_from_client = conn_obj.recv(2048) | |
if not msg_from_client: | |
print "<...No Relpy...> " | |
else: | |
print "FROM CLIENT ===> ", msg_from_client | |
# conn_obj.send("Thanks for your connection") | |
conn_obj.send(raw_input("TYPE A MESSAGE FOR CLIENT ==> ")) | |
conn_obj.close() | |
#Closing the socket | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment