Last active
December 31, 2016 09:35
-
-
Save hygull/626baeb916d9cbfddcef48a09713b8ab to your computer and use it in GitHub Desktop.
To implement a simple TCP client
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 client. | |
| @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 | |
| sock.connect(host_port_pair) #To actively intiate the TCP Server connection | |
| while True: | |
| print "TYPE A MESSAGE FOR SERVER ==> ", | |
| msg_for_server = raw_input() | |
| if not msg_for_server: | |
| break | |
| sock.send(msg_for_server) | |
| msg_from_server = sock.recv(2048) | |
| if not msg_from_server: | |
| print "<...No Reply from Server...>" | |
| else: | |
| print "From Server ==> ",msg_from_server | |
| sock.close() | |
| """ | |
| print type(sock.recv(2048)),sock.recv(2048) | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment