E1696 E0020 errors using VS

Pages: 123
I mean to say multiple instance of server that is run here and it has to sent all the received messages to all clients connected. How can we detect client disconnections? My understanding is that If the listening socket is not inside an accept() call when the client connects, the incoming connection gets queued.

Some sample code.
1
2
3
4
5
6
7
8
9
10

void SocketInstance::OnServerReceiveCallback(int32_t result,
                                                 const std::string& message) {
  // ...
  // received message
  server_.Write(message,
                    callback_fact_.NewCallbackWithOutput(
                      &SocketsInstance::OnServerReceiveCallback));
}



Below code for detecting disconnection client. Is this correct?

1
2
3
4
5
6
7
8
9
char buffer;
int length=recv(socket, &buffer, 0, 0);
int nError=WSAGetLastError();
if(nError!=WSAEWOULDBLOCK&&nError!=0){
    return 0;
}   
if (nError==0){
    if (length==0) return 0;
}
Last edited on
if you want multiple instances of the server, that is over my head... only way I know to do it is shared memory or interprocess communication of some sort. I don't know if the networking interface / tcpip protocol has something to make that easier.

if you drop a connection, for some amount of time, you just wait for... give it a time slice, and see if it has been reconnected. Your logic needs to ensure that the remote mac address or something matches and if so, put the new connection over the old one and resume. so when you get a new connection, if you have anything in your recently dropped storage/container, see if it matches and handle if it does, else its just a new connection.

I don't recall how to check if a connection has been closed. The web says if you try to read or write you can detect it ... look at some of the online examples.
Last edited on
do you mean to say to write a timeout function that handles for client disconnections by keep on listening for connections and then restart? Any way to find the list of available servers and send that info to client socket, so client can connect to one of them at a time.?
yes, you need to time them out if they do not recover after some reasonable time. For multiple servers, you need to push the restored guy back to the server it was on if it comes back online, which means shared info about dead connections. It would really be a lot easier if you just restart from scratch if dropped, if that is possible.
yes, you can get a list of servers. But what does that mean? are there multiple computers, or just multiple copies of the program, or both (many computers each running many copies?). There are many ways to do that... a shared memory block if all on the same machine, a little UDP broadcast if on a small network, a shared filesystem, whatever you think is appropriate... it can even be human configured text file, if it does not change after setup?
Last edited on
Yes, there are multiple computers that runs several servers. How can UDP broadcast be done to fetch server details as input to all clients?I start the server. I start client1 first and client2 second. When I type something in the console its client1's turn first so he receives the command. When I type something again client2 receives the command and so over and over.

I was wondering if there is a way to send it to all clients at the same time.?
Last edited on
You need to research this, its bigger than anything I have had to deal with.
I mean you "can" use udp -- each server broadcasts and listens, you can make a list from listening. And clients can listen to that, or you can have a master server that hands a client over to a lesser server ... but again, I do not know the best models to use for such a system.
Your requirements are unclear.

You're not really answering questions about your requirements, just going off and posting different code samples that don't seem directly related to what you want to do.

You started off wanting to know how to write a server. You've posted BSD socket samples, and more sample code using some network library. Now it seems you want some kind of sync between multiple computers ...

This is no way to tackle a complicated problem.

To help yourself, consider:
1. being clear about what you want help with
2. consider suggestions we make, so far you've pretty much ignored everything I've said
I am looking all possible options to try various suggestions from you. I am still learning it from the scratch.
Last edited on
There are too many things possibly you can do for anyone to keep answering these seemingly aimless questions,

If you want to learn network programming, you can, but you don't seem to want to go in that direction.

You seem to want to build a possibly complex system of synchronizing clients and server, but you haven't really said anything about it.

Typically, the way to learn about the underlying technologies, then apply them. Or, sort of know what you want to do, and learn enough to do that. But you don't seem to be doing either.
Last edited on
Registered users can post here. Sign in or register to post.
Pages: 123