Recent Posts

A journey to enter socket module in python 3x (Part 2)


If you missed part 1 then this article useless for you. So first kindly go part 1
and read that.


Now its time for create a client.py where the client send you a message.


import socket
host = '127.0.0.1'
port = 5000
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
    sock.connect((host,port))
except:
    pass

msg = input ('Durdin : ')
while msg!='q'
    msg = msg.encode('utf-8')
    sock.sendall(msg)
    data = sock.recv(1024).decode('utf-8')
    print('Devils says : ',data)
    msg = input('Durdin : ')

sock.close() 
 
 

Now its time for run those python code ^_^ .

How to run code ? I think you are kidding -_- !
But anyway i say that, if you are a linux user then if your file in Desktop
then you can run it by

python3.4 /root/Desktop/server.py
 If you are a root user. python3.4 this keyword is depend on your system. You can alias it from basr.rc by your terminal and make it as you want.
However if you can't notice your python version then just type on python shell and

import sys
sys.version

and you can know it.

Now here is the main point 

First run server.py
 

Then run  client.py from other terminal




Now you can notice a message appear in server.py



Now you can chat :) 



=====================================
 

Any confusion ?
I have also confusion :(




Post a Comment

0 Comments