烦恼的完成端口,求救!!!

huangxiaoke2000 2006-03-17 08:03:34
我用完成端口设计的服务器目前已经运行在Windows的服务器上,Win2003Server,双CPU,4个G内存。程序运行几个小时后,突然和所有的客户断开,然后显示的错误是:“由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。”,然后过了一会儿后,客户又慢慢的一个一个连接上来了。我的客户数不是非常多,大概在830个左右,可是数据传输很频繁,数量包不是非常大,最大2K。
不知道大家是否碰到过,请大家帮帮忙,出个主意啊。
...全文
243 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
borland_boy 2006-03-21
  • 打赏
  • 举报
回复
// Module Name: iocmplt.cpp
//
// Description:
//
// This sample illustrates how to develop a simple echo server Winsock
// application using the completeion port I/O model. This
// sample is implemented as a console-style application and simply prints
// messages when connections are established and removed from the server.
// The application listens for TCP connections on port 5150 and accepts them
// as they arrive. When this application receives data from a client, it
// simply echos (this is why we call it an echo server) the data back in
// it's original form until the client closes the connection.
//
// Compile:
//
// cl -o iocmplt iocmplt.cpp ws2_32.lib
//
// Command Line Options:
//
// iocmplt.exe
//
// Note: There are no command line options for this sample.

#include <winsock2.h>
#include <windows.h>
#include <stdio.h>

#define PORT 5150
#define DATA_BUFSIZE 8192

typedef struct
{
OVERLAPPED Overlapped;
WSABUF DataBuf;
CHAR Buffer[DATA_BUFSIZE];
DWORD BytesSEND;
DWORD BytesRECV;
} PER_IO_OPERATION_DATA, * LPPER_IO_OPERATION_DATA;


typedef struct
{
SOCKET Socket;
} PER_HANDLE_DATA, * LPPER_HANDLE_DATA;


DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID);

void main(void)
{
SOCKADDR_IN InternetAddr;
SOCKET Listen;
SOCKET Accept;
HANDLE CompletionPort;
SYSTEM_INFO SystemInfo;
LPPER_HANDLE_DATA PerHandleData;
LPPER_IO_OPERATION_DATA PerIoData;
int i;
DWORD RecvBytes;
DWORD Flags;
DWORD ThreadID;
WSADATA wsaData;
DWORD Ret;

if ((Ret = WSAStartup(0x0202, &wsaData)) != 0)
{
printf("WSAStartup failed with error %d\n", Ret);
return;
}

// Setup an I/O completion port.

if ((CompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0)) == NULL)
{
printf( "CreateIoCompletionPort failed with error: %d\n", GetLastError());
return;
}

// Determine how many processors are on the system.

GetSystemInfo(&SystemInfo);

// Create worker threads based on the number of processors available on the
// system. Create two worker threads for each processor.

for(i = 0; i < SystemInfo.dwNumberOfProcessors * 2; i++)
{
HANDLE ThreadHandle;

// Create a server worker thread and pass the completion port to the thread.

if ((ThreadHandle = CreateThread(NULL, 0, ServerWorkerThread, CompletionPort,
0, &ThreadID)) == NULL)
{
printf("CreateThread() failed with error %d\n", GetLastError());
return;
}

// Close the thread handle
CloseHandle(ThreadHandle);
}
WinEggDrop 2006-03-18
  • 打赏
  • 举报
回复
你要说清楚你那个软件是什么样的软件(HTTPD,FTPD,.....).
这样的错误,最大可能就是非页面缓冲池内存用尽,而以你给出的数据来看,800多个连接,最高的连接才2K/S的流量,在这样的配置系统中,是不应该将光非页面缓冲池内存的,那么如果上面我所说的假设都成立的话,那么肯定是你自己的软件有问题,很多非页面缓冲池内存被锁死,所以造成这样问题.
striking 2006-03-18
  • 打赏
  • 举报
回复
纯属猜测, 可能服务器投递完读,写操作后收到完成通知后, 不晓得什么时候被close了.
DentistryDoctor 2006-03-17
  • 打赏
  • 举报
回复
在一个尚未建立连接的“面向连接”套接字上发出数据收发请求便会产生这样的错误。
greenery 2006-03-17
  • 打赏
  • 举报
回复
完成端口是什么啊?
huangxiaoke2000 2006-03-17
  • 打赏
  • 举报
回复
晕啊
codeproject里的代码比较简单啊,只是入门性的
DentistryDoctor 2006-03-17
  • 打赏
  • 举报
回复
www.codeproject.com/internet
这儿有许多完成端口的例子。

应该是你哪没处理好,就你提供的信息,实难判断问题这所在。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧