web server - accept() method

B

Ben

hi all,

Just trying to figure out what the accept() method in socket.py does.

Lets consider the following webserver code:

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 8881
ock.bind(('',port))
....
....

while 1:
(newSock, addr) = sock.accept()
...
...

Here accept() returns newSock and addr. In my case "addr" holds the
value something like: ('127.0.0.1', 2571). What is 2571? This value
keeps changing each time i make a connection to above webserver. What
does this mean?

And also what is "newSock"? It holds value such as:
<socket object, fd=4, family=2, type=1, protocol=0>
What do i mean by this?

Thanks
Ben
 
G

Guest

Just trying to figure out what the accept() method in socket.py does.

On Unix you can check "man 2 accept", or even beter try to find the book
„UNIX Network Programming“ by Richard W. Stevens. Its a great book
Here accept() returns newSock and addr. In my case "addr" holds the
value something like: ('127.0.0.1', 2571). What is 2571? This value
keeps changing each time i make a connection to above webserver. What
does this mean?

That's the client address and port number.
And also what is "newSock"? It holds value such as:
<socket object, fd=4, family=2, type=1, protocol=0>
What do i mean by this?

newsock is a "socket", this one you use for communicating with the client.
The original socket is a listening one only...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,462
Latest member
ChanaLipsc

Latest Threads

Top