Saturday, March 14, 2015

Socket programming in python

Socket programming 'means' server-client model

So,we have to two python script. One for the server and one for the client.

For the server:

For the client
for the client and server python scripts click here
As you can see, the client is typing and sending a message and the  server is receiving and replying. If either the server or the clientwrites 'exit', then the connection stops.

The value of the HOST variable is the IP address of the client and the server... ( you can find IP, by pressing ifconfig in your terminal (for linux users) or by pressing ipconfig incommand prompt(for windows users)).

So if you want to achieve a communication between 2 computers (they must be connected in the same network) the steps are very simple:

1) In computer (A) you have to run the script for the server (don't forget the HOST variable)

2) In computer (B) you have to run the script for the client (don't forget the HOST variable)

No comments:

Post a Comment