TCP server shuts down when 1 of the clients terminates

I am constructing a program on TCP sockets. The server should be able to accept connections from more than 1 clients. My programs seem working fine when accepting connections. Now the problem is: when I try to terminate one of the client programs,
the server program would also terminate due to error in accept() (of course other client programs would terminate as well because the server shuts down). How can I keep the server running for listening and accepting new connections?

I may be wrong but as far as I see you are using a single port to receive client requests from , but later when you intend to handle different clients in different threads you have to bind them to a different port for the connection to remain intact and communication to take place. If all threads are linked to the same port and you close that port all the connections are bound to get disconnected.
As its been some time that I have programmed in this field I may have gone wrong somewhere. Do correct me in case I am wrong.

When I look at different examples on multiple-client socket programming, basically all of them uses the same port for listening and accepting connections from different clients, so I cannot judge whether this is the source of the problem or not.
Also, if the server have to use different ports for different clients, how can the client know which port on the server should it connect to? Since I have to assume that no. of clients is unknown, I guess I should not pre-assign the ports...

Naturally, you can have multiple connections to one port. Just think of an HTTP web server serving web pages to thousands of users connected on port 80.
The way you distinguish between clients is by socket number.

You should be checking for 'INVALID_SOCKET', and then calling WsaGetLastError to get a more detailed error code. Some of these error codes are not fatal, like EWSAWOULDBLOCK.

Next, you should not blindly call accept. There are nice ways to determine whether there is a new connection pending or new data in the buffer, ready to be received. Look at functions like 'select'. I know that on Linux there are better alternatives than select, I forgot if this is the case on Windows. In any case, select will do fine for a first try.

listen (basically) just tells the OS that you will be listening for new connections on this socket. It should only be called once, for each socket you want to listen on.

select-like functions tell you when there are new connections on a socket that you are listening on. You can have select behave differently by setting socket options like blocking or non-blocking. These things are documented extensively so just google a bit for when select is used, and how you can use it in your program.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...