如何解决在套接字上发送指针C ++
我已经设置了C ++客户端/服务器,我需要在它们之间传递一个指针(特别是uint8_t*
)。
编辑:指针指向的缓冲区
使用传统的send/recv
似乎不起作用(需要char*
),并且理想情况下,我会将这个指针作为带有其他变量的数据包的一部分发送。
做到这一点的最佳方法是什么?
服务器端进行说明:
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
int iResult = recv( this->ClientSocket,recvbuf,recvbuflen,0 );
if( iResult > 0 )
{
// ideally recvbuf would contain the pointer
// Do some stuff
// Send the buffer back to the sender
std::string result = "Message received";
// ideally here I would be sending my pointer,not this string
int iSendResult = send( this->ClientSocket,result.c_str(),(int)strlen( result.c_str() ),0 );
if( iSendResult == SOCKET_ERROR )
{
printf( "send failed with error: %d\n",WSAGetLastError() );
closesocket( this->ClientSocket );
WSACleanup();
return false;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。