TCP/IP Socket-Server Concurrent - sockets

I want to make a social network using a server and a client in Unix C. I know how to develop some minimalistic things about this architecture, but I want to make the server concurrent. What do you guys suggest me? Of course, not an iterative model ; I'm not going to use fork neither, because the server should accept clients, read from the clients and write to the clients. What about some threading methods or multiplexing?

I would suggest you to start with multiplexing.
Take a look at these functions
select http://manpages.courier-mta.org/htmlman2/select.2.html
epoll http://man7.org/linux/man-pages/man7/epoll.7.html
You can build your server around the reactor pattern http://en.wikipedia.org/wiki/Reactor_pattern

Related

How to use sockets in Lean?

How do I create a TCP socket in Lean 4 and accept an incoming connection or connect to a remote address? In other words, how do I implement a TCP server or client in Lean 4?
You need to wrap the socket types and functions to use them in Lean 4.
Lean 4 is still in an early stage, even without a stable release. There is very few packages for Lean now, so you cannot expect production level packages like Python's socket or Rust's std::net/mio.
But if you just want to take a try, you can look at my lean4-socket package, which is a toy implementation. There are also simple examples e.g. sending HTTP request (which is based on TCP) in the examples folder.
There is a rudimentary but working implementation of a socket API here which you can use with Lean 4 and Lake. It also has two examples that demonstrate its use.

Does VSCode use blocking communication with LSP

I'm playing around Language Server Protocol. After playing around for sometime I can see two way to communicate with the Language server, which is blocking sockets and non-blocking sockets.
By blocking socket I mean sending request and block until response. This is easy but It will block the UI once I use it in GUI application. Another one is using async/non-blocking sockets. This is a bit complex and might require some callback/event mechanism.
Now my question is which way does VSCode use to communicate with LSP?
The node language server implementation used by many extensions uses non-blocking communications. You can find the implementation here. It uses nodejs streams and the net module

Do I need to make clients support iocp when the server is iocp based?

I'm currently making 3d game with iocp based server.
My question here is that is there any reason in making clients support iocp io?
Because I think I only need one or two threads for io.
use iocp is one of way get notify when i/o request complete. your client can choose any way for this. this is absolute independent from way selected on server . client and server must use same protocol, crypto, etc. but not mandatory have common implementation details. client and server at all can run on different os.
so your client not obliged to use iocp. but however using iocp the best way here

Client server communication: REST vs Socket architecture

What are the advantages and disadvantages of using only socket based communication vs a hybrid of REST and socket (using socket only when bidirectional communication is necessary, like receiving messages in a chat).
When I say only socket, I mean that instead of sending a GET request asking for /entities, I'd send update_needed and the server would send a push via socket.
My question is not really about performance, it's more about the concept, like delegate vs block/lambda (using socket would be like the delegate concept and REST is more like block).
It all boils down to what type of application and level of scalability you have in mind.
WebSocket/REST: Client connections?
How to handle CQRS from a client-side perspective
Hard downsides of long polling?
The main reason why I wouldn't use WebSockets in any major project is simply that still many users don't use a modern browser that support them. Namely IE 8 and 9 don't support them and both together still have a market share of over 20 % (Oct 15).

how do I write my own production web server?

I am making a unix ssl server/client. So far I have implemented FD_SET with select to handle all connections concurrently in one master server process. However due to __FD_SETSIZE the number of clients can only be 1024. I need to increase the number of clients and efficiency of the server. Changing the __FD_SETSIZE has potential problems (apparently?) so I am stuck.
So far the network includes: errno.h detection, signal detection -> atomic handling, fd_set -> select(), successful stream socket based communication.
I would really appreciate it if someone can tell me what should I do? do I fork() after 1024 (which presents its own problems, if its even doable?) do I implement threads to handle each client request, or just client data or both?
What is the best network architecture in your opinion? keep in mind its a socket stream based connection that is meant to handle as much punishment as possible and allowing as many clients to the server as possible.
Don't write your own production web server.
There are too many open source servers out there all written by people who know more about high connectivity and SSL than you do. They also have the advantage of being tested to a degree that you'd never be able to accomplish with your homebrew server.