- #1
fog37
- 1,569
- 108
- TL;DR Summary
- Python Socket library to create server and clients
Hello,
I have been experimenting with the socket library in python creating small scripts, one called server.py and the other client.py, that can communicate with each other using a TCP protocol. The server script has an infinite loop that listens for request from the client.py script and responds to any requests. Both the "server" and the "client" are on the same physical machine, i.e. my computer. To make the communication possible, both server need to have the combination IP+port which represents a socket.
a) I know that name localhost represents an alias the local machine itself and corresponds to the IP 127.0.0.1. However, in my Python scripts, the IP used is the locally assigned IP (169....) which is different from 127.0.0.1....That said, when is 127.0.0.1 used? What is the purpose of it? Why isn't localhost the same as the assigned local IP address?
b) I always thought that for a program to be considered a "server", the program needed to be a sophisticated program capable of addressing multiple requests from multiple computers/clients at the same time and provide some service. But even a regular printer has a server program running on it, correct?
c) And some application seem to have a server/client structure in the sense that the application software is in the form of a server program. For example, MySQL is "server application" and the interface to it is the client. I wonder why some applications choose that architecture. Microsoft Word, Excel, PowerPoint, Adobe Acrobat, programs like Python, are not server programs. They are applications that when run also provide a user interface....
d) It is surely possible to send information from a computer to another connecting the computers with an ethernet cable as I have done in the past. That exchange of information does not involve any server though...Why? What is the difference then? Why do we need a server program?
thank you!
I have been experimenting with the socket library in python creating small scripts, one called server.py and the other client.py, that can communicate with each other using a TCP protocol. The server script has an infinite loop that listens for request from the client.py script and responds to any requests. Both the "server" and the "client" are on the same physical machine, i.e. my computer. To make the communication possible, both server need to have the combination IP+port which represents a socket.
a) I know that name localhost represents an alias the local machine itself and corresponds to the IP 127.0.0.1. However, in my Python scripts, the IP used is the locally assigned IP (169....) which is different from 127.0.0.1....That said, when is 127.0.0.1 used? What is the purpose of it? Why isn't localhost the same as the assigned local IP address?
b) I always thought that for a program to be considered a "server", the program needed to be a sophisticated program capable of addressing multiple requests from multiple computers/clients at the same time and provide some service. But even a regular printer has a server program running on it, correct?
c) And some application seem to have a server/client structure in the sense that the application software is in the form of a server program. For example, MySQL is "server application" and the interface to it is the client. I wonder why some applications choose that architecture. Microsoft Word, Excel, PowerPoint, Adobe Acrobat, programs like Python, are not server programs. They are applications that when run also provide a user interface....
d) It is surely possible to send information from a computer to another connecting the computers with an ethernet cable as I have done in the past. That exchange of information does not involve any server though...Why? What is the difference then? Why do we need a server program?
thank you!