UNIX & GNU/Linux - System calls - Using accept()

The accept() system call waits a connection from a client.

For the example above, we are going to take the nc tool (you can use telnet, it is the same).

If we reach the server through the nc connection, the server will shutdown.
But that's what we want to do.

UNIX & GNU/Linux - System calls - Using listen()

The listen() system call is designed to tell that a socket is ready to accept incoming connection.

Of course, we need first implementing the socket() and bind() system calls.

We are talking here about the server side.

UNIX & GNU/Linux - System calls - Using bind()

The bind() system call function is used with socket().

It assigns the address of the second argument to the file descriptor retrieved by socket().
Of course before using bind(), we must have a valid fd generated by socket().

UNIX & GNU/Linux - System calls - Using socket()

The socket() system call function will help us to create an end point.

This end point will allow for example to connect a client to a server.
Indeed, both of them (client and server) will have a socket() system call function on their implementation.

C++ - Tips'n Tricks - Using a list of pairs

The container list may accept another container.
For example a pair.

So we are trying to add pairs inside a list. It will become a list of pairs!

In the snippet below, I'm using only one file.
So just compile and execute it to see the result.

C - Character manipulation - Converting a char into an int

We can of course transform a char into an int with the atoi() function.

But what we are going to do now it's to create our own function to transform a string (several char) into a number.

UNIX & GNU/Linux - System calls - Using read()

We are going to use the read() function to read on the standard input from our favorite shell.

So each time you will write something then type ENTER, the text written will be display on the shell.

Let's see this, with this tiny tutorial of the read() function with a C example.

C - Keyword - Using extern

The extern keyword is designed to explicitely tells to someone seeing a variable in a code, that this variable has been firstly declared in another file.

So, even if you can choose to not use it, by convention and for a code more clear, you have to use it. 

The extern keyword works also with C++.

C++ - Algorithm - Using the for_each() function

An example of how using the for_each() function.

Notice that you can have the same result with an iterator, here an example.

C++ - STL (Standard Template Library) - Using the vector container

The vector container is the most classic STL container.

In the snippet below, I can iterate through the vector, so I use an iterator to erase an element of the vector.
In our case, I removed the number 2 from the container and I added 80 to this place.

Let's see this example of the vector container.

Pages

Subscribe to BadproG.com RSS