-
Create a new Socket and get its file descriptor.
Domain: Protocol family to be used (AF_INET)Type: Communication strategy (SOCK_STREAM)Protocol: The protocol to be used in the family with the socket type (0)
-
Set the options for the socket.
Level: The level of the options to be set. UseSOL_SOCKETfor socket level optionsOption_name: The name for the option to be passed to the protocol. Options likeSO_REUSEADDRshall override checks previous occupation of the same portOption_value: Set the value of the option to the value pointed
-
Use the
sockaddr_instruct to get and store the details of the connection.sin_family: Address family (AF_INET)sin_port: The port to use in 16-bit Network Byte Order (usehtons)sin_addr: The IP address in 32-bit Network Byte Order (useINADDR_ANYto connect to any network interface orINADDR_LOOPBACKto connect to127.0.0.1)sin_zero: Set it to0
-
Bind the socket to the
IP:port.Address: The interface IP address to bindPort: The port to bind to
-
Listen to the Socket.
Backlog: The maximum length, to which the queue of pending connections not established yet, may grow (1 - 128(system dependent))
The Server has been established! and it is listening to incoming requests Now, in an infinite loop,
-
Accept the first new incoming connection request and create a new socket with the new descriptor referring to it.
Address: Details of the connection stored above
-
As the connection is established, read the data from the file descriptor. Convert the received bytes data to String if required.
Count: Read the next count bytes from the file descriptorsBuffer: Store them is a buffer to process itFlags: Additional details for reading
-
Send a message to the client in bytes.
Socket: The new connection file descriptor to send the bytes toMessage: The message to be sent in bytes
-
Close the new file descriptor to close the connection.
Created
December 25, 2019 06:50
-
-
Save dev-ritik/5b6d0b17628abcd6c2b79090d77430ec to your computer and use it in GitHub Desktop.
Simple server program steps
Author
dev-ritik
commented
Jul 4, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment