Sockets for servers Flashcards

1
Q

How do berkeley sockets work for servers?

A

client actively initiates the connection
Server is passive, it waits and listens for an incoming connection from the
client
* Waits on a specific port (and possibly IP address)
* Start off as before by creating a socket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens next?

A

next they bind that socket to the port and IP address we want to use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how does binding work?

A

can either specify a specific IP address or ask it to listen on all interface using INADDR_ANY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does bind() function do?

A

socket is bound to the address and port

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we setup port for listening?

A

API provides a queue to allow multiple connections to queue up
* Once queue is full connections are refuse
* Can set the queue size when we set the socket to listen using the
listen() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what do we do when a connection happens?

A

use accept() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does accept() function do?

A

blocks until a connection is made
returns new socket descriptor for connection
returns client address of the connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What haooebs after contact has been made?

A

client and server are connected
server can speak to client
use recv() send()
once finsihed call close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how does server speak to client?

A

via the returned socket descriptor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What abt if theyre are multiple connections?

A

they arent processed until accept() is called again
so heart of our serve is normally an infinite loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what does this infinite loop do?

A

waits to accept connection
handles transaction
close connection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are multiple connections handled?

A

one by one
second connection wont open till first is closed
accept() has to be called immediatley after it returns
program needs to fork in 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly