假设我的头文件和一些包含的库没有问题。我正在使用 Winsock2。
//main.cpp and this code is okie, I omit some codes for readable reason
SOCKET ClientSocket;
ClientSocket = INVALID_SOCKET;
ClientSocket = accept(ListenSocket, NULL, NULL);
cout <<"a client is connected" << endl;
ClientConnection connection(ClientSocket);
connection.run();
//ClientConnection.h I tested any function and it's okie
class ClientConnection{
private:
SOCKET connectedSocket;
bool connected;
public:
ClientConnection(const ClientConnection &con);
ClientConnection(SOCKET s);
int processMessage(string message);
void sendMessage(string message);
string recvMessage();
int run();
void printSomething(); //function just print something such as :"Here"
};
在run()
函数中,我调用recvMessage()
以从客户端获取消息,然后调用processMessage(message)
. 这是我的processMessage(message)
和sendMessage
:
void ClientConnection::sendMessage(string mess){
const char* sendBuff = mess.c_str();
int error = send(this->connectedSocket,sendBuff, (int)strlen(sendBuff), 0);
delete sendBuff;
return ;
}
int ClientConnection::processMessage(string message){
cout << "This is message from client:\n" << message << endl;
ImageProcessingPlugin *plugin = new ImageProcessingPlugin();
plugin-> processMessage( *this, message);
delete plugin;
return 0;
}
这是 ImageProcessingPlugin:
// ImageProcessingPlugin.h
class ImageProcessingPlugin : public Plugin{
public:
ImageProcessingPlugin();
void processMessage(const ClientConnection &connection, string message);
};
// ImageProcessingPlugin.cpp
void ImageProcessingPlugin::processMessage(const ClientConnection& _connection, string message){
ClientConnection connection(_connection);
connection.printSomething() // It's okie
connection.sendMessage("Server received"); // Problem goes here!!
return;
}
调试后,当我调用printSomething()
时plugin->processMessage
,还是可以的,但是当我去的时候sendMessage
,客户端仍然从服务器收到消息“Server received”,但是出现错误:“_Block_Type_IS_VALID(pHead->nBlockUse)”!任何人都可以解决我的问题?