Sockets Flashcards

1
Q

Winsock API requires linking to what file?

A

ws2_32.lib

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

How is the DLL initialized for Winsock API?

A

WSAStartup()

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

What 2 parameters are passed to WSAStartup?

A
  1. WORD version
  2. WSAData data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 parameters passed to create a socket?

A
  1. int addressFamily
  2. int type
  3. int protocol
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the type parameter used when creating a socket for TCP?

A

SOCK_STREAM

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

What is the type parameter used when creating a socket for UDP?

A

SOCK_DGRAM

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

What is the address family parameter used when creating a socket?

A

AF_INET

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

What is the protocol parameter used when creating a socket for TCP?

A

IPPROTO_TCP

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

What is the protocol parameter used when creating a socket for UDP?

A

0

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

A server should first ______ a socket and then _____ the socket to its address and endpoint.

A

create, bind

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

What are the 3 parameters of the bind/connect function?

A
  1. SOCKET socket
  2. sockaddr *socketAddress
  3. int nameLength
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the nameLength for a socket?

A

sizeof(socketAddress)

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

How do you pass the socketAddress to the bind/connect function?

A

(SOCKADDR*)&socketAddress

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

What type is the socketAddress in bind/connect functions?

A

sockaddr_in

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

What 3 properties of sockaddr_in do we specify?

A
  1. sin_family
  2. sin_port
  3. sin_addr
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the socketAddress.sin_family?

A

AF_INET

17
Q

What is the socketAddress.sin_port?

A

htons(short port)

18
Q

How do you set the socketAddress.sin_addr?

A

inet_pton(AF_INET, “127.0.0.1”, &(socketAddress.sin_addr))

19
Q

What are the 2 parameters of the listen function?

A
  1. SOCKET socket
  2. int numberConnections
20
Q

What are the 3 parameters we used for the accept function?

A
  1. Socket
  2. NULL
  3. NULL
21
Q

What are the 5 steps to set up a socket on a server?

A
  1. Create socket using socket()
  2. Create socketAddress using sockaddr_in and inet_pton
  3. Bind the socket to the address using bind()
  4. Start listening using listen()
  5. Accept connections using accept()
22
Q

How do you close a socket?

A

closesocket()

23
Q

What’s the final function call in a socket application?

A

WSACleanup()

24
Q

What function is used to send data with TCP sockets?

A

send()

25
Q

What function is used to receive data with TCP sockets?

A

recv()

26
Q

What are the 4 parameters of the send/recv functions?

A
  1. SOCKET socket
  2. char* buffer
  3. int bufferSize
  4. int flags
27
Q

What 2 libraries are included for sockets?

A
  1. WinSock2.h
  2. WS2tcpip.h
28
Q

What is passed to htonl() if you want to accept connections from anywhere?

A

INADDR_ANY

29
Q

What function is used to send messages with UDP?

A

sendto()

30
Q

What function is used to receive messages with UDP?

A

recvfrom()

31
Q

What is the difference between the functions for sending/receiving messages between TCP and UDP?

A

UDP functions have 2 more parameters than TCP

32
Q

Which type of socket requires we specify the client address in the server?

A

UDP