【发布时间】:2012-06-18 03:52:26
【问题描述】:
假设我的头文件和一些包含的库没有问题。我正在使用 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;
}
经过调试,当我在plugin->processMessage中调用printSomething()时,还是可以的,但是当我转到sendMessage时,客户端仍然收到来自服务器的消息“服务器已接收”,但出现错误:“ _Block_Type_IS_VALID(pHead->nBlockUse)”!谁能解决我的问题?
【问题讨论】:
标签: c++ visual-c++ winsock2