- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要在端口 55005 向服务器发送多个请求(命令)。我的第一个请求得到处理成功,我也收到了。但是对于第二个请求,它会给出错误(WSAESHUTDOWN - 错误 10058)。在第一次请求后我打电话 关闭(ConnectSocket,SD_SEND);然后只有服务器处理第一个请求并向我发送输出。现在可以重新打开套接字处理下一个请求吗?**
我如何在关闭后处理多个请求(ConnectSocket,SD_SEND)?提前感谢您的建议。
我发送第一个请求,等待第一个回复。第一次请求回复后,我可以发送下一个请求。这是业务逻辑需求。我不想为每个请求打开一个新连接。
快照代码从这里开始 -------------->
**//This for loop will send multiple request to Servers.**
for(it = CommandList.begin(); it != CommandList.end() ; it++ )
{
//get each command request & send it to server.
std::string sendBuf; // = (*it);
sendBuf= *it;
int length = (int)strlen(sendBuf.c_str());
//----------------------
// Send an initial buffer
iResult = send( ConnectSocket, (char*)sendBuf.c_str(), length, 0 );
if (iResult == SOCKET_ERROR) {
wprintf(L"send failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
printf("Bytes Sent: %d\n", iResult);
// shutdown the connection since no more data will be sent
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
wprintf(L"shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
wprintf(L"Bytes received: %d\n", iResult);
else if ( iResult == 0 )
wprintf(L"Connection closed\n");
else
wprintf(L"recv failed with error: %d\n", WSAGetLastError());
} while( iResult > 0 );
}
最佳答案
正如 Joachim 所说,在完成连接之前不要调用 shutdown
。这个 TCP 套接字是一个“流”……东西可以随意来回。作为程序员,您必须确定“请求”和“响应”的开始和结束位置……不要为此使用 shutdown
。
关于c++ - WinSock 发送多个请求和关机问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14725674/
有没有人在 Windows 上使用 Winsock(不是 MSMQ)级别的 PGM 的经验?它看起来像是一个有用的可靠多播协议(protocol)(la TIBCO Rendezvous),我认为如果
我在 VS 2008 下使用 Winsock。 我有一个线程专门用于通过阻塞调用accept() 来接受传入的TCP 连接请求。当我的应用程序需要关闭时,我需要以某种方式解锁该线程,以便它可以执行关闭
在 KB4338830 更新后一段时间后,我们的应用程序突然持续卡住。不幸的是,应用程序无法重新启动也无法关闭,我怀疑这一切都是因为我正在使用的winsock(刚刚移植)。它是在vb.net上编写的,
我正在使用 Winsock API(不是 CAsyncSocket)来创建一个监听传入连接的套接字。 当有人尝试连接时,如何在接受连接之前获取他们的 IP 地址?我试图让它只接受来自某些 IP 地址的
服务质量 (QoS) 旨在管理带宽使用,这隐含地假设应用程序竞争该(有限)资源。这些天来,对于任何应用程序来说,这真的是一个问题吗? 它还假设 QoS 协议(protocol)和 Internet 协
我的项目使用 windows.h,其中使用了 winsock.h,我需要包含使用 winsock2 的 boost:assio。所以我收到很多错误,说 Winsock.h 已经包含在内。我可以定义 W
使用典型的 irc 客户端,我可以输入: /server localhost 6667 nick:pass 当我输入为 ZNC 配置的 nick:pass(IRC 保镖)时,我将被转发到在我的服务器/
我正在研究我面临的问题之一,与提出的问题类似 here .该问题基本上解决了客户端应用程序无法连接到数据库的问题。该解决方案似乎表明安装了与网络协议(protocol)不兼容的应用程序,我们应该卸载该
我一直在挠头,几个小时以来一直在寻找这个问题的答案。基本上我所做的就是打开一个到其他机器的套接字并从中读取数据。然后,通过传递表示套接字的 int 的 fdopen 调用,将该套接字“转换”为文件句柄
我在我的 VB6 应用程序中使用 winsock,这是我的代码: Private Sub Form_Load() With Winsock1 .Close .RemoteHo
我需要按照确定的顺序从客户端向服务器发送数据,服务器也可以按客户端发送的相同顺序接收这些数据。在下面的代码中,存在一个问题,即像下一个数据的数据一样接收数据(即控制字节 1 )。 前任: 在客户端上,
我正在开发客户端-服务器 Winsock 应用程序 (Visual C++),它应该通过网络传输各种数据(视频流、音频流、服务通知等)。我知道更简洁的方法是为每个单独的数据类型在单独的线程上使用单独的
我正在使用Microsoft Windows WinSock API拧小型HTTP服务器。 处理多个用户时是否需要应用多线程逻辑? 当前,Windows会在发生网络事件时发送一条消息,并且每条消息 (
对于我的项目,我无法调试程序,所以我无法确定为什么会出现此错误。 我的托管在 c# 上的服务器无法连接到本地主机上的服务器。 它没有向我的服务器发回“连接”信号,它永远不会连接,我认为代码写得很好,我
如何让 Winsock 程序只接受来自特定地址的连接请求?我希望被拒绝的连接被完全忽略,而不是得到 TCP 拒绝。 最佳答案 要使 Winsock 程序仅接受来自特定 IP 地址的连接,请使用 WSA
我写了一个数据包拦截器来转储来自winsock的send/recv函数的信息,据我所知,这两个函数都位于ws2_32.dll中;该钩子(Hook)是通过向一个函数写入一个 jmp 来完成的,该函数记录
我有一个简单的 winsock 程序,我想通过系统代理传递我的连接。我看到一些帖子解释了如何捕获系统代理然后发送如下字符串: CONNECT 127.0.0.1:8080 HTTP/1.0\r\n 等
我正在使用 tcp 套接字在 Windows XP 上的两个应用程序之间提供进程间通信。由于各种原因,我选择了 tcp 套接字。我看到平均往返时间为 2.8 毫秒。这比我预期的要慢得多。分析似乎表明延
我正在尝试在 Windows 下移植这个简单的 TCP echo 程序 ( https://github.com/mafintosh/echo-servers.c/blob/master/tcp-ec
过去两周我一直在学习 C,设法了解指针、数组和结构。 我想在 Windows 上进行一些套接字编程,想知道是否有人有任何提供教程和示例的网站,或者推荐一些使用 winsock 进行网络编程的书籍? 我
我是一名优秀的程序员,十分优秀!