Created
May 3, 2018 12:34
-
-
Save sudhanshuptl/680caf021199d7c84458dd3b3e7670d6 to your computer and use it in GitHub Desktop.
Basic Bidirectional server client communication. implemented in python (socket programming) #Python3
This file contains 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
#!/usr/bin/python # This is client.py file | |
import socket # Import socket module | |
s = socket.socket() # Create a socket object | |
host = socket.gethostname() # Get local machine name | |
port = 12345 # Reserve a port for your service. | |
s.connect((host, port)) | |
while True: | |
a = input("Enter the msg:") | |
s.send(bytes(a, 'ascii')) | |
recv = s.recv(1024) | |
print(str(recv)) | |
s.close() |
This file contains 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
#!/usr/bin/python # This is server.py file | |
#Python3 | |
import socket # Import socket module | |
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # Create a socket object | |
host = socket.gethostname() # Get local machine name | |
port = 12345 # Reserve a port for your service. | |
s.bind((host, port)) # Bind to the port | |
s.listen(5) # Now wait for client connection. | |
c, addr = s.accept() # Establish connection with client. | |
print('Got connection from', addr) | |
while True: | |
print(str(c.recv(1024))) | |
a = input("Enter the msg:") | |
c.sendall(bytes(a, "ascii")) | |
c.close() # Close the connection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment