Sockets Flashcards
Winsock API requires linking to what file?
ws2_32.lib
How is the DLL initialized for Winsock API?
WSAStartup()
What 2 parameters are passed to WSAStartup?
- WORD version
- WSAData data
What are the 3 parameters passed to create a socket?
- int addressFamily
- int type
- int protocol
What is the type parameter used when creating a socket for TCP?
SOCK_STREAM
What is the type parameter used when creating a socket for UDP?
SOCK_DGRAM
What is the address family parameter used when creating a socket?
AF_INET
What is the protocol parameter used when creating a socket for TCP?
IPPROTO_TCP
What is the protocol parameter used when creating a socket for UDP?
0
A server should first ______ a socket and then _____ the socket to its address and endpoint.
create, bind
What are the 3 parameters of the bind/connect function?
- SOCKET socket
- sockaddr *socketAddress
- int nameLength
What is the nameLength for a socket?
sizeof(socketAddress)
How do you pass the socketAddress to the bind/connect function?
(SOCKADDR*)&socketAddress
What type is the socketAddress in bind/connect functions?
sockaddr_in
What 3 properties of sockaddr_in do we specify?
- sin_family
- sin_port
- sin_addr
What is the socketAddress.sin_family?
AF_INET
What is the socketAddress.sin_port?
htons(short port)
How do you set the socketAddress.sin_addr?
inet_pton(AF_INET, “127.0.0.1”, &(socketAddress.sin_addr))
What are the 2 parameters of the listen function?
- SOCKET socket
- int numberConnections
What are the 3 parameters we used for the accept function?
- Socket
- NULL
- NULL
What are the 5 steps to set up a socket on a server?
- Create socket using socket()
- Create socketAddress using sockaddr_in and inet_pton
- Bind the socket to the address using bind()
- Start listening using listen()
- Accept connections using accept()
How do you close a socket?
closesocket()
What’s the final function call in a socket application?
WSACleanup()
What function is used to send data with TCP sockets?
send()