sendto 后错误值getlasterror为10038

herostarone 2010-11-15 05:50:17
for()
{
sendto(socket,。。。。);
cout<<socket<<endl;
}
发送了一会后socket的值都变了。
getlasterror显示10038,意思是在一个非套接字上尝试了一个操作。
但是我在里面加了一个sleep100ms,就没事,而sleep10ms都有同样的问题,为啥 啊
...全文
1117 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
herostarone 2010-11-15
  • 打赏
  • 举报
回复
我没关闭它啊,sendto了好多次才出的问题
[Quote=引用 2 楼 ouyh12345 的回复:]
是不是连接被关闭了?
[/Quote]
herostarone 2010-11-15
  • 打赏
  • 举报
回复
没有失败啊,我都sendto好多数据了,中间才出的问题

[Quote=引用 3 楼 visualeleven 的回复:]
socket()函数调用失败
[/Quote]
herostarone 2010-11-15
  • 打赏
  • 举报
回复
已经建立起来了,我都sendto好多数据了,中间才出的问题
[Quote=引用 1 楼 a19860903 的回复:]
sendto是udp发送方式,应该是对方socket还没创建起来
[/Quote]
Eleven 2010-11-15
  • 打赏
  • 举报
回复
10038: An operation was attempted on something that is not a socket.
Eleven 2010-11-15
  • 打赏
  • 举报
回复
socket()函数调用失败
ouyh12345 2010-11-15
  • 打赏
  • 举报
回复
是不是连接被关闭了?
疯狂石头_ 2010-11-15
  • 打赏
  • 举报
回复
sendto是udp发送方式,应该是对方socket还没创建起来
#pragma pack(4) //#include "stdafx.h" #pragma comment (lib,"Ws2_32.lib") #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include #include typedef struct iphdr { unsigned int headlen:4; unsigned int version:4; unsigned char tos; unsigned short totallen; unsigned short id; unsigned short falg; unsigned char ttl; unsigned char prot; unsigned short checksum; unsigned int sourceIP; unsigned int destIP; }IpHeader; typedef struct icmphdr { BYTE type; BYTE code; USHORT checksum; USHORT id; USHORT seg; }IcmpHeader; #define ICMP_RCHO 8 #define ICMP_RCHO_REPLY 0 #define ICMP_MIN 8 #define STATUS_FAILED 0xFFFF #define DEF_PACKET_SIZE 32 #define MAX_PACKET 1024 #define MAX_PING_PACKET_SIZE (MAX_PACKET+sizeof(IpHeader)) void fill_icmp_data(char *,int); USHORT checksum(USHORT *,int); void decode_resp(char *,int,struct sockaddr_in *); DWORD WINAPI FindIP(LPVOID pIPAddrTemp); WSADATA wsaData; SOCKET sockRaw; struct sockaddr_in dest,from,end; int fromlen =sizeof(from); char *recvbuf=new char[MAX_PING_PACKET_SIZE]; unsigned int addr=0; long ThreadNumCounter=0,ThreadNumLimit=20; long *aa=&ThreadNumCounter; void main(int argc,char *argv[]) { /*if(argc!=3) { cout<<"输入格式错误: start_ip end_ip"<Error()<Error()<ERROR) { cout<<"FAILED TO SEY RECV TIMEOUT"<Error()<ERROR) { cout<<"FAILED TO SEY RECV TIMEOUT"<Error()<error"id=(USHORT)GetCurrentThreadId(); datapart=icmp_data+sizeof(IcmpHeader); memset(datapart,'A',datasize-sizeof(IcmpHeader)); } void decode_resp(char *buf,int bytes,struct sockaddr_in *from) { IpHeader *iphdr; IcmpHeader *icmphdr; unsigned short iphdrlen; iphdr=(IpHeader*) buf; iphdrlen=iphdr->headlen*4; icmphdr=(IcmpHeader *)(buf+iphdrlen); if(bytestype!=ICMP_RCHO_REPLY)return; if(icmphdr->id!=(USHORT)GetCurrentThreadId())return; cout<<"活动主机: "<>16)+(cksum& 0xffff); cksum+=(cksum>>16); return (USHORT)(~cksum); } DWORD WINAPI FindIP(LPVOID pIPAddrTemp) { InterlockedIncrement(aa); char icmp_data[MAX_PACKET]; memset(icmp_data,0,MAX_PACKET); int datasize=DEF_PACKET_SIZE; datasize+=sizeof(IcmpHeader); fill_icmp_data(icmp_data,datasize); ((IcmpHeader*)icmp_data)->checksum=0; ((IcmpHeader*)icmp_data)->seg=0; ((IcmpHeader*)icmp_data)->checksum=checksum((USHORT*)icmp_data,datasize); int bwrote=sendto(sockRaw,icmp_data,datasize,0,(struct sockaddr *)pIPAddrTemp,sizeof(dest)); int n=0; if(bwrote==SOCKET_ERROR) { if(WSAGetLastError()==WSAETIMEDOUT) { cout<<"timed out"<sendto failies"<Error()<Error()==WSAETIMEDOUT) { cout<<"timed out"<ERROR) { if(WSAGetLastError()==WSAETIMEDOUT) { cout<<"timed out"<Error()<

18,356

社区成员

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

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