Protocols
● A protocol describes exactly how the communication should happen
● Necessary so the computer at the other end can understand the communication
● Remember no guaranteeing it will be the same type of computer
● Not necessarily complex, but must be precise..
Endianness
● Computer memory is addressed in bytes
● But often have to deal with things that are bigger than a byte
● How do the bits of these bigger entities get laid out into the bytes of memory
● Two approaches: Big Endian, and Little Endian
● Different machines have chosen different standards
Network Endianness
● The internet is standardised on being big-Endian
● Need to make sure the values in sin_port and sin_addr and big Endian (your machine may not be)
● Set of helper functions we can use to connect between network order and host order
● Basically, whenever you get a value in a network you use one of the ntohX() functions
● Whenever you set a value in network function, you use one of the htonX() function
● Designed to do nothing if not needed
, Initiating a connection from a client
Client server paradigm
● Connections are (generally) between two bits of software: the client and the server
● The server is software actively listening for a connection
● The client is software that connects to a server
● Need both to form an active connection
Creating a socket
● Create a socket using the socket() function
● Need to tell it what domain we want the socket in, the type of connection we want and the protocols
● Returns the file descriptor for the created socket or -1 if an error occurred
● A protocol describes exactly how the communication should happen
● Necessary so the computer at the other end can understand the communication
● Remember no guaranteeing it will be the same type of computer
● Not necessarily complex, but must be precise..
Endianness
● Computer memory is addressed in bytes
● But often have to deal with things that are bigger than a byte
● How do the bits of these bigger entities get laid out into the bytes of memory
● Two approaches: Big Endian, and Little Endian
● Different machines have chosen different standards
Network Endianness
● The internet is standardised on being big-Endian
● Need to make sure the values in sin_port and sin_addr and big Endian (your machine may not be)
● Set of helper functions we can use to connect between network order and host order
● Basically, whenever you get a value in a network you use one of the ntohX() functions
● Whenever you set a value in network function, you use one of the htonX() function
● Designed to do nothing if not needed
, Initiating a connection from a client
Client server paradigm
● Connections are (generally) between two bits of software: the client and the server
● The server is software actively listening for a connection
● The client is software that connects to a server
● Need both to form an active connection
Creating a socket
● Create a socket using the socket() function
● Need to tell it what domain we want the socket in, the type of connection we want and the protocols
● Returns the file descriptor for the created socket or -1 if an error occurred