Sockets for clients Flashcards

1
Q

What are connections between?

A

client and the server

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

what is the server?

A

software actively listening for a connection

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

What is the client?

A

software that connects to a server

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

Do we need both?

A

yes we need both to form an active connection

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

benefits of TCP connections?

A

reliable and steam oriented connection

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

What do machines need to be doing?

A

1 needs to be listening for connection and the other needs to connect to that open port

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

What is the connection type?

A

Bi-directional

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

What does a protocol describe?

A

how the communication should happen
order bits are sent in
what individual bits mean

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

What is the Http protocol?

A

send a request and get a repsonse
simple requests are easy

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

What is the de facto API for TCP/IP?

A

Berkeley sockets

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

What do sockets API use?

A

recv(), send(), close()

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

do we open a connection?

A

no rather we create socket using socket()
which is one end of our connection and theres another socket at the other end

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

What does client need?

A

create a socket with socket()
connect to a server using connect()
transfer data using send()/recv()
close the connection using close()

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

How do we create socket?

A

use socket() function
tell what domain we need socket in
type of connection we want
the protocol
returns the file descriptor for created socket or -1 if errors

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

How do we connect?

A

use connect() function
socket needs to be connected to other end of connection
need address of the end point
ip address of machine and port to connect to
use struct sockaddr_in to contain details

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

What needs to be done when closing connection?

A

both ends of connection need to close it

17
Q

What are 2 approaches to convert into bytes of memory?

A

Big endian and little endian

18
Q

What happens in big endian?

A

most significant byte stored at lowest memory address 12,34,56,78

19
Q

What happens in little Endian?

A

least significant byte are stored at the lowest memory address
78,56,34,12

20
Q

What is the internet standardlised as?

A

big endian

21
Q

what do sin_port and sin_addr values need to be made sure of?

A

that they big endian

22
Q

what is the ntohX() function?

A

whenever you get a value in a network you use it
it converts network byte to host byte ordering

23
Q

What is the htonX() function?

A

whenever you set a value in a network function you use it
it converts host byte to network byte ordering

24
Q

What does getaddrinfo do?

A

returns linked list of potential ip addresses to connect to then you can try to connect to each one
returns 0 if everything ok

25
Q

what does getaddrinfo consist of?

A

dns hostname string
string containing service
hints
address of a PTR

26
Q

what does getaddrinfo return?

A

return multiple addresses with multiple connection types
we can either search the linked list or provide some hints to reduce the list

27
Q

what is hint provided as?

A

a pointer and we need to free the function as well

28
Q

What do we need to be careful of when reading?

A

data comes in packets so might not get all in one go so check return value of recv() to see how much was read
then check if it contains what we expect

29
Q

What does recv() do if no data available?

A

will block until some sent
and return 0 when connection is closed

30
Q

how do we close?

A

both client and server must close the connection

31
Q

How does it know when to close?

A

theres an explicit end of communication phrase in protocol
When this is sent server closes connection
When client reads it, it closes connection