Client & Server Sockets & Exceptions Flashcards

1
Q

This demonstrates that, from an OS perspective, different either a client or a server.

A

NOPE once a socket is created it is neutral, can be used for both

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

The host part of the server address can be either

A

hostname, ip or empty string

‘127.0.0.1’ or ‘localhost’ loopback address

if hostname it used DNS but non-deterministic and may return IPv4 or IPv6

empty string a server can accept IPv4 connections on all available interfaces

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

Port numbers range

A

0 - 65535

0-1023 well-known
1024 - 49151 registered
49152 - 65535 dynamic, private and ephemeral

when socket bound to address, cannot be changed (cannot bind twice)

when closed the binding is released but not immediately (TCP WAIT_TIME)

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

s = socket(AF_INET,SOCK_STREAM)
print(s)
s.bind((SERVER_HOST,SERVER_PORT))
print(s)

A

after binding we get the laddr

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

What about binding on the client side?

A

happens implicitly (to local address with ephemeral port)

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

how to know client port on client side vs. server port?

A

cs.getsockname()
cs.getpeername()

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

If you try to call the listen
method without binding

A

it will raise an OSError Exception.

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

regular sockets vs. listening sockets

A

server client
vs
server

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

which function accepts the optional backlog parameter

what does it do

A

listen()

determines the how many connections can be pending before refusing other connections
1 - socket.SOMAXCONN

128 linus
5-200 windows

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

On Windows, to verify that a socket is listening on a specific port, use the following
command on cmd:

A

netstat -aon

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

What method puts the program into blocking mode?

A

accept()

returns connection (regular socket for send\recv) and address

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

examples of gaierror exceptions

A

getaddrinfo(“ “, 80)
gethostbyname(‘gooogggle.com’)
gethostbyaddr(‘127.412.14.10’)
or anything with a weird ip

connect((‘hello’, 70000))
bind((‘hellobitch’, 80000))

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

what functions could cause timeoutError

A

at client
connect()
create_connection ()
recv()

at server
accept()
recv()

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

s = socket()
s.bind((‘localhost’,800000))

A

overflowError

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

s.send(‘hello’)

A

TypeError

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

in_msg = s.recv(-5)

A

valueError

17
Q

print(s.getsockname()[3])

A

index error

18
Q

s.receivall(1024)

A

attributeError