Home > Software engineering >  The problem of TCP service multithreaded receiving data
The problem of TCP service multithreaded receiving data

Time:10-21

Recently wrote a server to communicate with others, because want to use thread receives the data, so using a CreateThreadh function under FD_READ events, and in class thread functions declared in a static RecvProcv (), but at run time, the thread function socket, address and so on were tip is not defined, but the socket of the variables are defined in the class, speed to teach!!!!!

CodePudding user response:

You need to create a socket, and accept with the client's connection, binding, and then you can read data

CodePudding user response:

"I/O model network programming" search on the net,
Or refer to the http://blog.csdn.net/woshinia/article/details/8585930
According to the specific business need to modify the

CodePudding user response:

Post code to see general because there are no initialization

CodePudding user response:

Thread synchronization problem, cause uninitialized variables, thread function is invoked

CodePudding user response:

Thread function is a class of static function, can not be directly using the class member variables,
Solution, 1 was introduced into the object in the thread function pointer, thread function through a pointer to access class members;
Two is the use of c + + 11, simple, and adopted a more flexible

CodePudding user response:

Static member functions of class can't directly access ordinary member function of a class or member variables, but in turn ordinary member function can access a static member function or static member variables, this is a c + + foundation ~

CodePudding user response:

5 6 floor right
  • Related