Working with threads right now. I have the "normal main thread" and a client/serverReceiver thread.
Although, I got one problem. I need to share objects, more specifically the socket and/or the clientlist.
Socket in the client, because I send in the "main" thread and receive in a subclass, ClientReceiver, who use the same socket, obviously.
I'm not sure how to do this in a proper way without the mess of billions and billions of pointers, alright that's an exaggeration, two or three.
How do I share a vector created in my Client class with the ClientReceiver class?
pseudo code could look like this:
class Server{
SocketTCP listener;
ServerReceiver recv;
vector <SocketTCP > clientlist;
void runRegularly(){
sendSometimes;
recv.Launch(); //RUN THREAD
}
}
class ServerReceiver : Thread{
SocketTCP *socketFromServer;
vector<SocketTCP > *clist;// PROBLEM. HOW DO I STORE A POINTER TO A VECTOR?
func initialize(SocketTCP s, vector c ){ // PROBLEM. HOW DO I PASS A POINTER TO A VECTOR?
scoketFromServer = s;
clist=c;
}
func Launch(){
acceptSockets(putTheSocketInThisSharedVector);
receive();
}
}
I'll be using mutexes around the vector and socket just to be safe :roll:
Is the structure even remotely correct? Sharing stuff between threads and classes seem like a thing you shouldn't do.
Main problem right now is the vector.
Without it I can't get the Sockets for the clients in the server. They're "in" the selector (not in the "code" snippet, I know, but that's a problem for another day).
Anyways, it's late and I'm tired as heck and I hope you understand my ramblings.
Any help would be appreciated.