recvfrom接收不到数据了 [问题点数:40分,结帖人puj2003]

Bbs1
本版专家分:15
结帖率 97.06%
Bbs1
本版专家分:15
Bbs9
本版专家分:87215
Blank
状元 2017年 总版技术专家分年内排行榜第一
Blank
榜眼 2014年 总版技术专家分年内排行榜第二
Blank
探花 2013年 总版技术专家分年内排行榜第三
Blank
进士 2018年总版新获得的技术专家分排名前十
2012年 总版技术专家分年内排行榜第七
Bbs1
本版专家分:16
Bbs1
本版专家分:15
Bbs1
本版专家分:0
recvfrom接收不到数据,求解
用SmartSniff抓包看到<em>接收</em>缓冲区里有<em>数据</em>,可是用<em>recvfrom</em><em>接收</em><em>数据</em>时,有时可以<em>接收</em>到<em>数据</em>,有时却收<em>不到</em><em>数据</em>,求解释。
recvfrom接受不到数据
在服务端发送<em>数据</em>给客户端,发送代码如下:rn[code=C/C++]sockaddr_in remote; rnremote.sin_addr.S_un.S_addr = htonl((*ServerIterator)->ip); rnremote.sin_family = AF_INET;rnremote.sin_port = htons((*ServerIterator)->port);rnrnint isend = sendto(m_PrimaryUDP, (const char *)&realmessage, sizeof(realmessage), 0, (const sockaddr*)rn&remote, sizeof(remote)); rn/* rnrealmessagewei为发送的内容,remote为客户端地址,m_PrimaryUDP为一个套接字rn经调试,发送没问题,发送内容和地址都没问题。rn*/[/code]rnrn但是客户端没有接受到任何<em>数据</em>,不知道哪出问题了rn接受代码如下rn[code=C/C++]sockaddr_in sender; rnstMessage recvbuf; //接受<em>数据</em>的结构体rnmemset(&recvbuf, 0, sizeof(stMessage));rn<em>recvfrom</em>(socket, (char *)&recvbuf, sizeof(stMessage), 0, (sockaddr *)&sender, &dwSender);[/code]rn调试发现recvbuf为空,可是不明白怎么会为空呢???rnrn望高人指点一二 rn
XP系统下IPv6 recvfrom()接收不到数据问题!恳求指教!
我用的是原始套接字winsock=WSASocket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6,NULL, 0,0);//发送ICMPv6报文,rnrc=sendto(winsock,SendBuf, sizeof(SendBuf),0,res->ai_addr,res->ai_addrlen);rn但是用rnret = <em>recvfrom</em>(winsock,(char *)RecvBuf,1024,0,(SOCKADDR *)&remote6,&len6);<em>接收</em><em>不到</em>返回的响应ICMPv6报文rn是不是我写错了?请各位大虾指点一二,在此谢过了!有兴趣可和我联系QQ:275374701潘元勇(真名)源码很简单VC++6.0下的rnrnrnwinsock=WSASocket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6,NULL, 0,0);//rn if(winsock==INVALID_SOCKET)rn rn AfxMessageBox("创建本机socket失败");rn return ;rn rn elsern rn AfxMessageBox("创建本机socket成功");rn rnrnrnrn //绑定本地监听端口bindrn/* if(bind (winsock,res->ai_addr,res->ai_addrlen)==SOCKET_ERROR) rn rn rn AfxMessageBox("bind失败");rn return;rn rn rn elsern rn AfxMessageBox("bind成功"); rn rn*/rn rc=getaddrinfo((LPCTSTR )m_ip6destaddr,"2000",&hints,&res);//解析目的地址rnfor(int i=1;i< 0));rnrn //WSAIoctl(winsock, SIO_RCVALL,&RecvBuf, sizeof(RecvBuf),&RecvBuf, sizeof(RecvBuf),&RecvBufR, NULL, NULL);rn //BOOL on = TRUE;rn //setsockopt(s_send, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on));rn /* int on = 1;rnrn setsockopt(s_send, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on));rn setsockopt(s_send, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, sizeof(on));rn setsockopt(s_send, IPPROTO_IPV6, IPV6_HOPOPTS, &on, sizeof(on));rn setsockopt(s_send, IPPROTO_IPV6, IPV6_DSTOPTS, &on, sizeof(on));rn setsockopt(s_send, IPPROTO_IPV6, IPV6_RTHDR, &on, sizeof(on));rn */rn //ret = setsockopt(s_send, IPPROTO_ICMPV6, IP_HDRINCL, (char *)&on, sizeof(on));rn //填充ICMPV6头部rn static unsigned short seq_no = seq_no+1;rn icmpHdr.icmp_type =m_icmpv6type;rn icmpHdr.icmp_code = 0;rn icmpHdr.icmp_cksum = 0;rnrn#ifdef WIN32rn icmpHdr.icmp_id = (unsigned short)GetCurrentProcessId(); rn#elsern icmpHdr.icmp_id = (unsigned short)getpid(); rn#endifrn icmpHdr.icmp_seq = seq_no++;rnrn#ifdef WIN32rn icmpHdr.icmp_timestamp = (unsigned long)::GetTickCount();rn#elsern icmpHdr.icmp_timestamp = (unsigned long)time(NULL);rn#endifrnrn icmpHdr.icmp_cksum = CheckSum((unsigned short*)SendBuf, sizeof(IcmpHeader) + 0);rn udpHdr.src_portno = htons(1024);//);// htons(SRC_PORT);rn udpHdr.dst_portno = htons(1111);//m_p.in_destportrn udpHdr.udp_length = htons(sizeof(udpHdr)+512) ;rn udpHdr.udp_checksum = 0 ;rn //写入缓冲区SendBufrn ZeroMemory(SendBuf, 1024);rn ptr=SendBuf;rn memcpy(ptr, &icmpHdr, sizeof(icmpHdr));rn //ptr += sizeof(icmpHdr);rn// memcpy(ptr, &udpHdr, sizeof(udpHdr));rn //发送<em>数据</em>rn memset(&source6, 0, sizeof(struct sockaddr_in6));rn source6.sin6_family=AF_INET6;rn source6.sin6_port=0;rn source6.sin6_flowinfo=0;rnrnrn memcpy((char*)&source6.sin6_addr, &res->ai_addr,res->ai_addrlen);rn// rc=sendto(winsock,SendBuf, sizeof(SendBuf),0,(struct sockaddr *)&source6, sizeof(struct sockaddr_in6));rn rc=sendto(winsock,SendBuf, sizeof(SendBuf),0,res->ai_addr,res->ai_addrlen);rn if (rc== SOCKET_ERROR)rn rn AfxMessageBox("发送失败");rn closesocket(winsock);rn WSACleanup();rn return;rn rn elsern rn // AfxMessageBox("发送成功");rn Sleep(1000);rn rn //<em>接收</em><em>数据</em>rn ZeroMemory(RecvBuf, 1024);rn// remote6.sin6_family=AF_INET6;rn// remote6.sin6_port=0;rnrn // ret = recv(winsock,RecvBuf,sizeof(RecvBuf),0);rn rn // ret = <em>recvfrom</em>(winsock,(char *)RecvBuf,1024,0,(SOCKADDR *)&remote6,&len6);rn ret = <em>recvfrom</em>(winsock,(char *)RecvBuf,1024,0,(SOCKADDR *)&res->ai_addr,&len6);rn int nError = WSAGetLastError(); rn message.Format("%d",nError);rn AfxMessageBox(message);rn if(ret);rn rn //10014rn //Sleep(1000);rnrn写的很烂,目的在于实验!拜托大家啦!
sniffer 能抓到包,为什么用recvfrom接收不到数据??
写了一个客户端程序,向服务器请求<em>数据</em>,用的是udp协议,socket编程。其中第一了两个套接字,sock1、sock2,其中sock1绑定1201端口负责向服务器发送请求命令;sock2绑定1202端口。现在用sniffer抓到服务器发送过来的<em>数据</em>包,发送到本地的1202端口。我再程序中写了<em>recvfrom</em>();接受<em>数据</em>,可是<em>recvfrom</em>返回值为零。求大侠指教!!!
jrtp接收不到数据
这是我的<em>接收</em>端的源代码:[code=css]#include "rtpsession.h"rn#include "rtppacket.h"rn#include "rtpudpv4transmitter.h"rn#include "rtpipv4address.h"rn#include "rtpsessionparams.h"rn#include "rtperrors.h"rn#include rn#include rn#include rn#include rn#include rn#include rnrn#include "rtpsourcedata.h"rnrnclass MyRTPSession : public RTPSessionrnrnprotected:rn void OnPollThreadStep();rn void ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack);rn;rnrnvoid MyRTPSession::OnPollThreadStep()rnrn BeginDataAccess();rn // check incoming packetsrn if (GotoFirstSourceWithData())rn rn dorn rn RTPPacket *pack;rn RTPSourceData *srcdat;rn rn srcdat = GetCurrentSourceInfo();rn rn while ((pack = GetNextPacket()) != NULL)rn rn rn ProcessRTPPacket(*srcdat,*pack);rn DeletePacket(pack);rn rn while (GotoNextSourceWithData());rn rn rn EndDataAccess();rnrnrnvoid MyRTPSession::ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack)rnrn printf("got packet!\n");rnrnrnint main()rnrn MyRTPSession sessrecv;rn short portbase;rn std::string ipstr;rn int status,num;rnrn // First, we'll ask for the necessary informationrn rn portbase=8020;rn num=10;rn int i;rn RTPUDPv4TransmissionParams transparams;rn RTPSessionParams sessparams;rn sessparams.SetOwnTimestampUnit(1.0/8000.0); rn rn transparams.SetPortbase(portbase);rn status = sessrecv.Create(sessparams,&transparams); rn checkerror(status);rn rn // Wait a number of secondsrn for(i=0;i
关于recvfrom接收超时
<em>recvfrom</em>,这方法如果不特意设置,默认
解决recvfrom阻塞接受问题
<em>recvfrom</em>阻塞<em>接收</em>的问题,网络不通就一直等,想改成非阻塞的,也不可靠谱。最后设置了一个超时时间 struct timeval tv_out; tv_out.tv_sec = 3;//等待10秒 tv_out.tv_usec = 0; setsockopt(sock_fd,SOL_SOCKET,SO_RCVTIMEO,&tv_out, sizeof(tv_out))
关于udp socket recvfrom函数的一个易错问题: 如果应用程序指定的接收长度不够怎么办?
我们来看这样一个问题, 在udp socket变成中, sendto连续三次发送10个字节的<em>数据</em>,
epoll中使用recvfrom 获取不到对端的ip和port
一、 epoll 之后的socket <em>recvfrom</em>的时候,需要设置          socklen_t socklen = sizeof(struct sockaddr);    //一定要初始化为sizeof,如果为0 则出错 m_data_len = <em>recvfrom</em>(m_fd, m_data, sizeof(m_data), 0, (struct sockaddr*)&amp;amp;m_...
linux udp 客户端recvfrom,一直没有数据接收,谁能帮看看这代码哪里出了问题了????
void* StartDiscoveryThread(void *arg) { int so_broadcast=1; struct sockaddr_in toAddr; //客户端的网络地址。 struct sockaddr_in serverAddr; //服务器端的网络地址。 char inBuff[DD_BUFF_LEN]; int sockaddrLen = 0; in
NMUDP接收不到数据
我现在用NMPUDP实现一个UDP小程序,发送程序可以实现,但是<em>接收</em><em>不到</em><em>数据</em>,<em>接收</em>事件是通过NMUDP1DataReceived实现的,但是<em>接收</em><em>不到</em><em>数据</em>的问题出现了,用断点调试,发现程序根本不执行该函数内容,这是为什么呢?谁来帮忙解决下啊。。。灰常感谢
at指令接收不到数据
过程状态如下:rn 使用超级终端能够和手机正常通讯,发送:at,返回:OK, 关闭睡眠:at+eslp=0其他通用指令都能使用。然后关闭超级终端,重启手机,用自己的程序打开串口,发送指令,都能<em>接收</em>得到。关闭程序,重启手机几次后,用自己的程序和手机执行以上命令,都正常返回。rn int Init()rn rn char ans[128]=0; // 应答串rnrn // 测试GSM-MODEM的存在性rn WriteComm("AT\r", 3);rn ReadComm(ans, 128);rnrn if (strstr(ans, "OK") == NULL)rn rn return 0;rn rnrn //AT+ESLP=0 关闭睡眠rn WriteComm("AT+ESLP=0\r", 10);rn ReadComm(ans, 128); rn rnrn int WriteComm(void* pData, int nLength)rn rn DWORD dwNumWrite; // 串口发出的<em>数据</em>长度rn WriteFile(hComm, pData, (DWORD)nLength, &dwNumWrite, NULL);rn return (int)dwNumWrite;rn rnrn int ReadComm(void* pData, int nLength)rn rn DWORD dwNumRead; // 串口收到的<em>数据</em>长度rn ReadFile(hComm, pData, (DWORD)nLength, &dwNumRead, NULL); rn return (int)dwNumRead;rn rnrn 拔掉<em>数据</em>线,重新插入。开启自己的程序,连接手机,打开串口,发送指令。此时<em>接收</em><em>不到</em>任何应答<em>数据</em>。rn不知道为何?rn rnrn rn rn
为什么接收不到数据
我写的上位机程序,用串口助手可以<em>接收</em>到它发来的<em>数据</em>,问什么它<em>接收</em><em>不到</em>串口助手发过来的<em>数据</em>,下面是它<em>接收</em><em>数据</em>的代码,大家帮我看看,谢谢!rnrnprocedure TForm1.Button7Click(Sender: TObject);rnrnvarrndata:string;rnBufferLength:word;rnBuffer:Pointer;rnbegin rnSetLength(data,BufferLength);rnmove(Buffer^,pchar(data)^,Bufferlength);rnMemo1.lines.Add(data);rnMemo1.Invalidate;rnrnend;
Receive()接收不到数据
出问题的程序段如下:rnwhile(!bExit)rnrn // 等待主线程传来Accept生成的socket值rn ::WaitForSingleObject(MyView->ReceiveStart.m_hObject, INFINITE);rnrn // 准备开始互斥完成工作rn if (localLock->Lock(0)) rn rn MyView->ReceiveStart.ResetEvent();rn recvSocket.Attach(MyView->m_RecvSocket);// 获得当前这个socketrn MyView->AcceptNow.SetEvent(); rn localLock->Unlock(); // 解锁rn recvdSize = recvSocket.Receive((char*)&recved_pkt, sizeof(PKT));rn if (recvdSize == SOCKET_ERROR) ;rn elsern ;rnrn说明:MyView是指向View的指针,m_RecvSocket是一个View的成员变量,保存Accept时生成的socket,其它一些是CEvent的对象,用来完成线程间同步。rnrnrn每次recvdSize都是SOCKET_ERROR, 即使其中那句“recvSocket.Attach(MyView->m_RecvSocket)”(对Attach()我的理解不太深)改成recvSocket.m_hSocket = MyView->m_RecvSocket.m_hSocket, 也会报错,错误编号10038(WSAENOTSOCK)。真是摸不着头脑,希望有行家能给我解答一下。rnrn多谢多谢!!
网络编程,接收不到数据
刚开始学网络编程,写了个小程序测试了一下,老是第一次<em>接收</em><em>不到</em><em>数据</em>,但是就是能<em>接收</em>到结束标志,郁闷。rn一小段代码如下:rnrn 服务端: while(1)rn rn printf("abc\n");rn bzero(buffer2,sizeof(buffer2));rn n=read(pthread->clientsocket,buffer2,sizeof(buffer2));rn printf("read=%d\n",n);rn printf("%s\n",buffer2);rn if(strcmp(buffer2,"quit")==0)rn break;rn rn fwrite(buffer2,n,1,fp);rn rn rn printf("recv over\n");rn fclose(fp);rnrnrn 客服端:rn fd=open(mp.filename,O_RDWR);rn if(fd==-1)rn rn perror("open file error!");rn exit(1);rn rn lseek(fd,0,SEEK_SET);rn bzero(buffer,sizeof(buffer));rn while((n=read(fd,buffer,sizeof(buffer)))>0)rn rn m=write(socket2,buffer,strlen(buffer));rn printf("write=%d\n",m);rn printf("%s\n",buffer);rn sleep(1);rn bzero(buffer,sizeof(buffer));rn rn close(fd);rn bzero(buffer,sizeof(buffer));rn strcpy(buffer,"quit");rn sleep(1);rn write(socket2,buffer,strlen(buffer));rn printf("%s\n",buffer);rn printf("update file over!\n");rnrnrn 客服端终端信息如下:rn Update Files:b.c //输入文件,打印如下rn write=11rn 123456rn 789rnrn quitrn update file over!rnrnrn 服务端终端信息如下:rn abcrn read=4rn quitrn recv over //每次客服端输入文件名,服务端就只打印这四句。rnrnrn 求高手指正一下!
idUdpServer 接收不到数据
在ActiveFormX中使用idUdpServerrn//初始化rnwith idUDPServer1.Bindings.Add dornbeginrn IP:='';rn Port:=6013;rnend;rnidUDPServer1.active:=True;rnrn//idUDPServer1UPPRead 事件处理rnshowmessage('hello');rnrn该程序在ie中使用程序打开后rn用天网防火墙观察看到 ie有在UDP 6013端口监听rn当服务端发来<em>数据</em>时候rn天网防火墙发现ie有在UDP 6013端口监听目的指向了rn服务端ip端口也正确 rn但程序没有按设计的那样出提示rn点了一下IE的刷新 发现程序出 'hello' 提示了rn好像ie 不会把<em>数据</em>提交给程序 只在要刷新时一下提交rn这怎么回事rn希望大家帮助
GCDAsyncSocket 接收不到数据
GCDAsyncSocket <em>接收</em><em>不到</em><em>数据</em>
电脑接收不到数据?
电脑连上网络后,<em>接收</em><em>不到</em><em>数据</em>,查看IP都是正确的,但是PING不通网关,本机能PING通,是怎么回事?
串口接收不到数据
各位大侠:rn 最近在写一个吊称<em>数据</em>获取程序,通过RS232获取<em>数据</em>,但是吊称跟电脑连接后,C#程序获取<em>不到</em>任何<em>数据</em>,serialPort1_DataReceived事件不能触发,不知道是什么原因?请问怎么样才能<em>接收</em>到串口的<em>数据</em>?我将自个电脑的串口2,3脚短接就能接受到自己发出的<em>数据</em>!rn
后端接收不到数据
@RestController @RequestMapping("/itemsearch") public class ItemSearchController { @Reference private ItemSearchService itemSearchService; @RequestMapping("/search") public Map&lt;St...
openwithparm接收不到数据
如题,我在w_1中添加了一个按钮,按钮的clicked事件中代码如下:rnlong ll_rowrnstring ls_nbrrnint li_countrnll_row = dw_1.rowcount()rnif ll_row > 0 thenrn ls_nbr = dw_1.object.do_mstr_do_nbr[dw_1.getrow()]rn select count(*) into :li_count from tr_histrn WHERE tr_nbr=:ls_nbr;rn if li_count>0 thenrn messagebox('提示','仓库已经输入<em>数据</em>,你无法修改该单据!')rn return -1rn elsern openwithparm(w_2, ls_nbr)rn end if;rnend if rn在w_2的open中代码如下:rnstring ls_message,ls_deptrnrnrnls_message = message.stringparmrnis_nbr= ls_messagernrndw_1.retrieve(is_nbr)rn用messagebox来条显示在w_1中的代码有实现,且debug运行有看到message.stringparm有值,但是打开了w_2后,就为空,rn请高手不吝赐教
完成端口接收不到数据
#include "Server.h"rn#include rn#include rn#include rnrnstatic DWORD WINAPI subThread( LPVOID lpParameter )rnrn DWORD bytesCnt;rn HANDLE cphdl = ( HANDLE )lpParameter;rn SOCKET sock;rn LPOVERLAPPED pOverLapped;rn char *buf;rnrn while( 1 ) rn GetQueuedCompletionStatus( cphdl, &bytesCnt, ( PULONG_PTR )&buf, rn ( LPOVERLAPPED * )&pOverLapped, INFINITE );rnrn std::cout << bytesCnt << std::endl;rn rnrn return 0;rnrnrnbool Server::create()rnrn WSADATA wsaData;rn WSAStartup( MAKEWORD( 2, 2 ), &wsaData );rnrn // 1. create a completion portrn HANDLE cpHdl = CreateIoCompletionPort( INVALID_HANDLE_VALUE, 0, 0, 1 );rn // 2. Create Socketrn SOCKET sock = createSock();rn // 3. create threadrn DWORD subThrdId;rn HANDLE thrdHdl = CreateThread( 0, 0, subThread, ( LPDWORD )cpHdl, 0, &subThrdId );rn CloseHandle( thrdHdl );rn // 4. listenrn startListen( sock, cpHdl );rnrn return true;rnrnrnSOCKET Server::createSock()rnrn SOCKET sock;rn sockaddr_in saServer;rn sock = WSASocket( AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED );rn saServer.sin_family = AF_INET;rn saServer.sin_addr.s_addr = inet_addr( "127.0.0.1" );rn saServer.sin_port = htons( 5150 );rn bind( sock, ( SOCKADDR * )&saServer, sizeof( saServer ) );rn listen( sock, 1 );rn return sock;rnrnrnvoid Server::startListen( SOCKET sock, HANDLE cpHdl )rnrn SOCKET acceptSock;rn char *buf = ( char * )GlobalAlloc( 0, 256 );rn WSABUF wsaBuf = 256, buf ;rn DWORD bytesCnt;rn DWORD flag = 1;rn WSAOVERLAPPED overLapped;rn bool ret = false;rnrn while( 1 ) rn acceptSock = WSAAccept( sock, NULL, NULL, 0, 0 );rn std::cout << "accept" << std::endl;rn CreateIoCompletionPort( ( HANDLE )acceptSock, cpHdl, ( DWORD )buf, 1 );rn ZeroMemory( &overLapped, sizeof( overLapped ) );rn char *msg = "main thread";rn WSARecv( acceptSock, &wsaBuf, 1, &bytesCnt, &flag, &overLapped, 0 );rn send( acceptSock, msg, strlen( msg ), 0 );rn int err = WSAGetLastError();rn rnrnrn不明白问题出在哪里,一些关键步骤都有检查过,没有什么错误。还请高手指教rn
UDP接收不到数据
服务端代码:rn private void lxcMain_Load(object sender, EventArgs e)rn rn int recv;rn byte[] revData = new byte[1024];rn byte[] sendData = new byte[1024];rn IPAddress address = IPAddress.Parse("192.168.31.80");rn IPEndPoint ip = new IPEndPoint(address, 6667);rn Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);rn newsock.Bind(ip);rn IPEndPoint sender1 = new IPEndPoint(address, 0);rn EndPoint Remote = (EndPoint)(sender1);rn recv = newsock.ReceiveFrom(revData, ref Remote);rn rn客户端代码放在板子上通过以太网连接。rn代码在项目中ReceiveFrom<em>接收</em><em>不到</em><em>数据</em>。新建一个测试项目复制同样代码就可以<em>接收</em><em>数据</em>了。 请问,可能会有什么原因造成?
recv接收不到数据!!
while(1)rn rn byte_count = recv(sock, buf, sizeof(buf), 0);rn if(byte_count>0)rn rn return 1;rn rn elsern rn continue;rn rn rn 这样都<em>接收</em><em>不到</em><em>数据</em>。郁闷中................
为什么recvfrom接受不到数据啊?
我的代码如下:rnrn PacketMessage packMessage;rn int saLen = sizeof( packMessage.NasRemote ) ;rn bzero(&packMessage,sizeof(PacketMessage));rn while(true)rn rn int pnLen = <em>recvfrom</em>(socket,packMessage.data,MAX_RESPONSE_PACKET_LEN,0,(struct sockaddr *)&(packMessage.NasRemote),(socklen_t *)&saLen);rn if (pnLen < 0) rn rn printf ("Received Packets Failed , Now Exit The Program , Please Contact Your Administrator !\n ");rn rn printf("NasAddr:%s",inet_ntoa(packMessage.NasRemote.sin_addr));rn rnrnrn这是怎么回事呢???rn
recvfrom接收速度问题
UDP发送端FPGA一次发过来256个包,包长512字节,包跟包之间的间隔是100ns,FPGA以及电脑的速度都是千兆的。我自己编写的UDP<em>接收</em>软件只能<em>接收</em>十几个包……在网上有看到说调用一次<em>recvfrom</em>要花掉大约5.7us,这个<em>数据</em>可靠吗?如果真是这样的情况的话,那岂不是只有缓冲区中的<em>数据</em>包可以收到了吗?该怎么改善这样的情况!!!rnrn有没有别的办法进行网络编程,可以使<em>接收</em><em>数据</em>包的速度快些呢?(我用的是VC6.0,用vs2008的话,这种情况会得到改善吗?)rn这个问题困扰了我好久,望各位高手帮忙分析分析呀!谢谢哦!rn
recvfrom接收的问题
程序是这样的:一线程用于<em>接收</em>,另一个线程用于发<em>数据</em>rn两个线程共用一个socket,阻塞模式<em>recvfrom</em>rn问题是:mobile手机上,开机第一次运行正常,也能收<em>数据</em>,rn当我关闭相关的资源,退出之后,第二次运行该程序,出现能发<em>数据</em>,却不能收<em>数据</em>rn相关的系统资源,每次退出都释放掉,包括socket,shutdown再closehandle....rnrn哪位大哥帮忙一下
recvfrom() 接收线程阻塞
在一个线程中用 <em>recvfrom</em>()循环去读<em>数据</em>,设置为非阻塞,并用到select()。rnrn该<em>接收</em>线程会阻塞。但网卡已经<em>接收</em>到<em>数据</em>。
recvfrom接收失败
BOOL CChatDlg::initsocket()rn rn SOCKET m_socket=socket(AF_INET,SOCK_DGRAM,17);rn if(m_socket==INVALID_SOCKET)rn rn MessageBox("套接字创建失败");rn return FALSE;rn rn SOCKADDR_IN sockaddr;rn sockaddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY);rn sockaddr.sin_family=AF_INET;rn sockaddr.sin_port=htons(6512);rn int len;rn len=sizeof(SOCKADDR);rn bind(m_socket,(SOCKADDR*)&sockaddr,len);rn return TRUE;rnrnrnoninitrn initsocket();rn TIAN *tian=new TIAN;rn tian->sock=m_socket;rn tian->hwnd=m_hWnd;rn HANDLE handle=CreateThread(NULL,0,SockProc,(LPVOID)tian,NULL,NULL);rn CloseHandle(handle);rn rn线程函数rnDWORD WINAPI CChatDlg::SockProc(LPVOID lpParameter)rnrn SOCKET sock=((TIAN*)lpParameter)->sock;rn HWND hwnd=((TIAN*)lpParameter)->hwnd;rn //delete lpParammeter;rn SOCKADDR_IN addrfrom;rn int len=sizeof(SOCKADDR);rn char recvbuf[200];rn char tempbuf[200];rn int recv;rn while(TRUE)rn rn recv=<em>recvfrom</em>(sock,recvbuf,200,0,(SOCKADDR*)&addrfrom,&len);rn if(recv==SOCKET_ERROR)rn rn AfxMessageBox("套接字接受失败");rn break;rn rn sprintf(tempbuf,"%s say: %s",inet_ntoa(addrfrom.sin_addr),recvbuf);rn ::PostMessage(hwnd,WM_RECVDATA,0,(LPARAM)tempbuf);rnrn rn return 0;rnrn
recvfrom()消息的接收问题
关于这个<em>recvfrom</em>()函数,现在是不知道什么时候该用它来读取消息,rn我在BCB下做个聊天的软件,不想用控件,所以就没有事件了,那么什么时候来让客户端<em>接收</em>消息呢?rn不能用按钮来读取吧,rn我是新手,请求帮助,苦思好几天了,嘿嘿,rnrn
recvfrom接收数据报失败
向本机发包,<em>接收</em>时使用rnrecvBytesCount = <em>recvfrom</em>(hsock,recvByte,BUFSIZE,0,(LPSOCKADDR)&s_sockaddr,&recvsize);rn有的时候成功有的时候失败,失败时的返回值为timeout,不知道这是什么原因.使用时没有设置s_sockaddr.rn最郁闷的是在别人的机器上运行时每次都能成功!
UDP的recvfrom接收问题
有三台电脑rnA: IP:192.168.1.2,Mask:255.255.255.0, 网关:192.168.1.16rnB:IP:192.168.1.13,Mask:255.255.255.0, 网关:192.168.1.16rnC:IP:192.168.0.2,Mask:255.255.255.0, 网关:192.168.0.16rnB作为A和C的信令解释中间方,要与A、C通信,均使用UDP协议rnA中程序a的<em>接收</em>端口是2000rnB中程序b的<em>接收</em>A的端口是2001rnB中程序b的<em>接收</em>C的端口是10000rnC中程序c的<em>接收</em>B的端口是10000rn主要症状是:rnb可以<em>接收</em>到a和c的<em>数据</em>,但从抓包软件(Ethereal)上看到,A和C的<em>数据</em>包到达了B(比如100个),b大部分能处理(大约80到90个左右),并没有全部处理。rnb程序是用VC写的命令行程序,网络方面直接使用Winsock的API写的网络,要写记录到磁盘文件中。rn分别创建了<em>接收</em>A和C的线程,所用的都是基本的API,就是不知道什么原因?rnUINT RecvCMsg(LPVOID pvParam)rnrn SOCKADDR_IN tosin;rn int tolen = sizeof(SOCKADDR_IN);rn memcpy(&tosin, &SendCtosin, tolen);rnrn int r=0;rn SOCKADDR_IN fromaddr;rn int fromlen=sizeof(SOCKADDR_IN);rn while (TRUE)rn rn char* pBuffer=new char[256];rn retlen = <em>recvfrom</em>(RecvCSock, pBuffer, 256, 0, (SOCKADDR*)&fromaddr, &fromlen);rn if (retlen, r);rn delete[] pBuffer;rn rn r++;rn rn return 0;rnrn尝试解决方法:rn1、调试时发现主要是<em>recvfrom</em>那阻塞了,按道理有<em>数据</em>来时(抓包软件上看到),<em>recvfrom</em>应该返回的而不应该继续阻塞。现在的问题好像在<em>recvfrom</em>阻塞,错过几个包后再响应过来。rn2、听说UDP应用上,<em>接收</em>和发送是不能一个端口的,但B新创建了一个NewCSock(比如说10001端口的socket),sento时,这个新socket代替10000端口产生的socket,C却收<em>不到</em>B发过去的<em>数据</em>包。rnsendto(RecvCSock, buffer, retlen, 0, (SOCKADDR*)&tosin, tolen);改为rnsendto(NewCSock, buffer, retlen, 0, (SOCKADDR*)&tosin, tolen);rn3、<em>recvfrom</em>之前用select的方法也还是这个问题rn4、会不会是处理函数中有sendto,然后使用<em>recvfrom</em><em>接收</em>会出现问题?rn请高手们指教!!!!十分感谢!
程序为什么接收不到组播的消息?recvfrom一直不返回
[code=c]#include rn#include rnrn#pragma comment( lib, "ws2_32.lib")rnrnint main()rnrn WSADATA wsadata;rn SOCKET Socket, socket;rn SOCKADDR_IN from, to;rnrn WSAStartup( 0x0202, &wsadata );rnrn printf("初始化完毕!\n");rn Socket = WSASocket( AF_INET, SOCK_DGRAM, 0, NULL, 0, WSA_FLAG_MULTIPOINT_D_LEAF|WSA_FLAG_MULTIPOINT_C_LEAFrn |WSA_FLAG_OVERLAPPED);rnrnrn if( !Socket )rn rn printf( "创建socket失败: %d\n", WSAGetLastError() );rn return 0;rn rn printf("socket建立\n");rnrn from.sin_family = AF_INET;rn from.sin_port = htons( 1000 );rn from.sin_addr.S_un.S_addr = htonl(INADDR_ANY);rn rn to.sin_family = AF_INET;rn to.sin_port = htons( 4804 );rn to.sin_addr.S_un.S_addr = inet_addr( "224.40.40.40" );rnrn if( bind( Socket, (SOCKADDR*)&from, sizeof(from) ) == SOCKET_ERROR )rn rn printf( "bind失败: %d\n", WSAGetLastError() );rn return 0;rn rn printf("bind完成\n");rnrn if( ( socket = WSAJoinLeaf( Socket, (SOCKADDR*)&to,sizeof(to),NULL,NULL,NULL,NULL, JL_BOTH)) == SOCKET_ERROR )rn rn printf("WSAJoinLeaf()失败: %d\n",WSAGetLastError());rn closesocket(Socket);rn WSACleanup();rn return 0;rn rn printf("joinleaf\n");rnrn while( 1 )rn rn char recvbuffer[100];rn int value = 0;rn int len = sizeof(to);rn rn memset( recvbuffer, 0, 100);rn value = <em>recvfrom</em>( socket, recvbuffer, 100, 0, (struct sockaddr*)&to, &len);rnrn printf("value = %d\n",value);rn printf( "%s\n", recvbuffer );rn rnrn closesocket(Socket);rn closesocket(socket);rn WSACleanup();rn return 0;rn[/code]rn通过拦包发现,明明有向224.40.40.40:4804发送了<em>数据</em>,可是程序为啥收<em>不到</em>?求指点
问题:gprs_dtu接收不到数据?
BOOL DSGetNextData(DtuDataStruct* pDataStruct,u16t waitseconds)rn功能:读取下一条Dtu送上来的信息rn参数:pDataStruct: 存放Dtu所送上来的信息和<em>数据</em>的结构,读函数执行成功后,返回的<em>数据</em>存放到该参数指向的结构中rnwaitseconds:本函数读到<em>数据</em>后立即返回;如果没有<em>数据</em>到达,则等待最长waitseconds(时间单位:秒)的时间,直到有<em>数据</em>到达,取值范围从0~65535,如果取值为0表明本函数将立即返回。另外,当在另一个线程中执行成功了DSStopService()后,本函数将立即返回。rn返回:如果返回为非零值,表明收到了一条Dtu信息。如果返回为0,则表明没有收到<em>数据</em>。rnrnrn上面是gprs_dtu<em>数据</em><em>接收</em>函数,我设定每5秒执行一次,为什么每次都读<em>不到</em><em>数据</em>呢?有谁做过这方面,给点意见啊。rnrn听人说,可能是啥维系连接,注册包之类的问题 ,不懂啊
udp通讯接收不到数据
http://www.cnblogs.com/keyvip/archive/2010/11/16/1878713.html用的这个大神的代码rn我用的delphi xe7rn<em>接收</em>端<em>接收</em><em>不到</em><em>数据</em>,用网上其它的网络调试工具可以<em>接收</em>到<em>数据</em>rnprocedure TForm1.idpsrvr1UDPRead(AThread: TIdUDPListenerThread;rn const AData: TStream; ABinding: TIdSocketHandle);rn var Comm:TCommBlock;rnbeginrn AData.ReadBuffer(Comm,SizeOf(Comm));rn mmo1.Lines.Add('Comm');rnend;rn是不是这个函数有问题?初学,请大神指点。谢谢
raw socket接收不到数据
初学网络编程,照网上的例子写了个sniffer程序,可是执行到recv的时候,就没有返回了,估计是超时。请高人指点:rnrn[code=C/C++]rn#include "StdAfx.h"rn#include "Sniffer.h"rnrn#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)rn#define BUFFER_SIZE 65535rnchar RecvBuf[BUFFER_SIZE];rnrnUINT SniffThreadFun(LPVOID pParam);rnvoid SignalHandler(int sig);rnrnSniffer::Sniffer(void)rn : stopSniff(true)rnrnrnrnSniffer::~Sniffer(void)rnrnrnrnbool Sniffer::InitSocket(void)rnrn int err;rn int sockOpt = 1;rn char localName[100];rn struct hostent *hostPtr;rn SOCKADDR_IN sockAddr;rnrn WORD versionRequired = MAKEWORD(1,1);rn err = WSAStartup(versionRequired, &wsaData);rn if(err == SOCKET_ERROR)rn return false;rn sockRaw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);rn if (sockRaw == INVALID_SOCKET)rn return false;rn err = setsockopt(sockRaw, IPPROTO_IP, IP_HDRINCL, rn (char*)&sockOpt, sizeof(sockOpt));rnrn if (err == SOCKET_ERROR)rn return false;rn err = gethostname(localName, sizeof(localName)-1);rn if (err == SOCKET_ERROR)rn return false;rn hostPtr = gethostbyname(localName);rn if (hostPtr == NULL)rn return false;rn sockAddr.sin_addr = *(in_addr *)hostPtr->h_addr_list[0];rn sockAddr.sin_family = AF_INET;rn sockAddr.sin_port = htons(57274);rn err = bind(sockRaw, (PSOCKADDR)&sockAddr, sizeof(sockAddr));rn if (err == SOCKET_ERROR)rn return false;rn return true;rnrnrnbool Sniffer::StartSniff(void)rnrn stopSniff = false;rn int err;rn unsigned long arg = 1;rnrn err = ioctlsocket(sockRaw, SIO_RCVALL, &arg);rn if (err == SOCKET_ERROR)rn int errCode = WSAGetLastError();rn return false;rnrn AfxBeginThread(rn (AFX_THREADPROC)SniffThreadFun, rn (LPVOID)this, rn THREAD_PRIORITY_NORMAL, rn 0, 0, NULL);rnrn return true;rnrnrnbool Sniffer::StopSniff(void)rnrn stopSniff = true;rn Sleep(2000);rn int err;rn DWORD arg = 0;rn err = ioctlsocket(sockRaw, SIO_RCVALL, &arg);rn if (err = SOCKET_ERROR)rn return false;rnrn return true;rnrnrnvoid Sniffer::DisposeSocket(void)rnrn WSACleanup();rn closesocket(sockRaw);rnrnrnUINT SniffThreadFun(LPVOID pParam)rnrn Sniffer *snifferPtr = (Sniffer *)pParam;rnrn while(!snifferPtr->stopSniff)rn rn //[color=#FF0000]执行recv的时候没有返回[/color]rn if (recv(snifferPtr->sockRaw, RecvBuf, BUFFER_SIZE, 0))rn rn snifferPtr->recvCallback(snifferPtr->pObserver, RecvBuf);rn rn rnrn return 0;rnrn[/code]
通信上了接收不到数据
实现个远程注销功能 初学IOCP想试试 通信成功了 但<em>接收</em><em>数据</em>好象收<em>不到</em> 点完注销按钮没反映,找不出什么毛病rn烦劳高手慧眼识错 感激不尽rnrn服务端IOCP模型rn#include rn#include rn#define BUFFER_SIZE 1024rnrntypedef struct _PER_HANDLE_DATArnrn SOCKET s;rn sockaddr_in addr;rnPER_HANDLE_DATA,*PPER_HANDLE_DATA;rnrntypedef struct _PER_IO_DATArnrn OVERLAPPED ol;rn char buf[BUFFER_SIZE];rn int nOperationType;rn#define OP_READ 1rn#define OP_WRITE 2rn#define OP_ACCEPT 3rnPER_IO_DATA,*PPER_IO_DATA;rnrnchar *ID="PowerOff";rnDWORD WINAPI ServerTheard(LPVOID lpParam);rnrnvoid main()rnrn WORD wVersionRequested;rn WSADATA wsaData;rn int err;rn rn wVersionRequested = MAKEWORD( 2, 2 );rn rn err = WSAStartup( wVersionRequested, &wsaData );rn if ( err != 0 ) rn return;rn rn rn rn if ( LOBYTE( wsaData.wVersion ) != 2 ||rn HIBYTE( wsaData.wVersion ) != 2 ) rn WSACleanup( );rn return; rn rn HANDLE hCompletion=CreateIoCompletionPort(INVALID_HANDLE_VALUE,0,0,0);rn CreateThread(NULL,0,ServerTheard,(LPVOID)hCompletion,0,0);rn rnrn SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);rn SOCKADDR_IN addrSrv;rn addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);rn addrSrv.sin_family=AF_INET;rn addrSrv.sin_port=htons(12345);rn rn bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));rn rn listen(sockSrv,5);rn rn SOCKADDR_IN addrClient;rn int len=sizeof(SOCKADDR);rnrn while(1)rn rn rn SOCKET sockConn=accept(sockSrv,(SOCKADDR*)&addrClient,&len);rn PPER_HANDLE_DATA pHandle=(PPER_HANDLE_DATA)GlobalAlloc(GPTR,sizeof(PPER_HANDLE_DATA));rn pHandle->s=sockConn;rn memcpy(&pHandle->addr,&addrClient,len);rn CreateIoCompletionPort((HANDLE)pHandle->s,hCompletion,(DWORD)pHandle,0);rn rn PPER_IO_DATA pIo=(PPER_IO_DATA)GlobalAlloc(GPTR,sizeof(PPER_IO_DATA));rn pIo->nOperationType=OP_READ;rn rn WSABUF buf;rn buf.buf=pIo->buf;rn buf.len=BUFFER_SIZE;rn DWORD dwRecv;rn DWORD dwFlags=0;rn WSARecv(pHandle->s,&buf,1,&dwRecv,&dwFlags,&pIo->ol,NULL);rn rn rnrnrnrnrnDWORD WINAPI ServerTheard(LPVOID lpParam)rnrn HANDLE hCompletion=(HANDLE)lpParam;rn DWORD dwTrans;rn PPER_HANDLE_DATA pHandle;rn PPER_IO_DATA pIo;rnrn while (TRUE)rn rn BOOL bOK=GetQueuedCompletionStatus(hCompletion,&dwTransrn ,(LPDWORD)&pHandle,(LPOVERLAPPED*)&pIo,WSA_INFINITE);rn if (!bOK)rn rn closesocket(pHandle->s);rn GlobalFree(pHandle);rn GlobalFree(pIo);rn continue;rn rn if (dwTrans==0&&(pIo->nOperationType==OP_READ||pIo->nOperationType==OP_WRITE))rn rn closesocket(pHandle->s);rn GlobalFree(pHandle);rn GlobalFree(pIo);rn continue;rn rn switch(pIo->nOperationType)rn rn case OP_READ:rn rn rn if (ID==pIo->buf)rn rn ExitWindowsEx(EWX_LOGOFF,0); //就是实现个远程注销功能rn rn WSABUF buf;rn buf.buf=pIo->buf;rn buf.len=BUFFER_SIZE;rn DWORD dwRecv;rn DWORD dwFlags=0;rn WSARecv(pHandle->s,&buf,1,&dwRecv,&dwFlags,&pIo->ol,NULL);rn rn break;rn case OP_WRITE:rn break;rn case OP_ACCEPT:rn break;rn rn rn rn return 0;rnrnrn客户端:rnrnchar *ID="PowerOff";rnvoid CPowerOffDlg::OnBtnPoweroff() rnrn // TODO: Add your control notification handler code herern send(m_sock,ID,strlen(ID)+1,0);rn rn
关于SOCKET接收不到数据
发送端:rn结构体rntypedef struct head_packetrnrn char type[20]; //类型rn int length; //长度rn char aque[20]; //序列号 rn ST_HEAD_PACKET;rn发送<em>数据</em>:rn strncpy(head_package->type , "log" , sizeof("log"));rn head_package->length = strlen(head_package->type);rn strncpy(head_package->aque , "log" , sizeof("log"));rnrn writen(sd , head_package, sizeof(struct head_packet));rn函数:rnssize_t writen(int fd, const void *ptr, size_t n)rnrn size_t nleft;rn ssize_t nwritten;rnrn nleft = n;rn while (nleft > 0) rn if ((nwritten = write(fd, ptr, nleft)) < 0) rn if (nleft == n)rn return(-1); /* error, return -1 */rn elsern break; /* error, return amount written so far */rn else if (nwritten == 0) rn break;rn rn nleft -= nwritten;rn ptr += nwritten;rn rn return(n - nleft); /* return >= 0 */rnrn<em>接收</em>端:rn head_package = (ST_HEAD_PACKET *)malloc(sizeof(struct head_packet));rn memset(head_package , 0 , sizeof(struct head_packet));rn readn(sd , head_package , sizeof(head_package));rn printf("%s\n" , head_package->type);rn printf("%s\n" , head_package->aque);rn问题:rn<em>接收</em>端只能收到head_package->type 不能<em>接收</em>到head_package->aque
wince 串口接收不到数据
各位麻烦给指点一下,我的串口<em>接收</em>长时间<em>接收</em>之后就<em>接收</em><em>不到</em><em>数据</em>了,不知道怎么解决,还望各位帮忙看看!下面是我的<em>接收</em>线程,过几个小时后就<em>接收</em><em>不到</em><em>数据</em>了,我的线程<em>接收</em>来自模块的串口<em>数据</em>,模块不停的每隔400毫秒发一次<em>数据</em>rnDWORD CRsCom::CommRecvTread(LPVOID lparam)rnrn DWORD dwLength;rn char *recvBuf = new char[512];rn CRsCom *pDlg = (CRsCom*)lparam;rn COMSTAT ComStat;rn DWORD dwErrorFlags;rn PurgeComm(pDlg->m_hComm,PURGE_RXCLEAR|PURGE_TXCLEAR); //清空串口的<em>接收</em>缓 冲区,必要性不大rn ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat); //清除串口状态标rn while(TRUE)rn rn PurgeComm(pDlg->m_hComm,PURGE_RXCLEAR|PURGE_TXCLEAR); //清空串口的<em>接收</em>缓 冲区,必要性不大,但有rn //ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat); //清除串口状态标rn if (WaitForSingleObject(pDlg->m_ExitThreadEvent, 0) == WAIT_OBJECT_0 )rn break; rn if (pDlg->m_hComm != INVALID_HANDLE_VALUE )rn rn ClearCommError(pDlg->m_hComm,&dwErrorFlags,&ComStat);rn BOOL fReadState = ReadFile(pDlg->m_hComm, recvBuf, 512, &dwLength, NULL);rn if(!fReadState)rn rn //MessageBox(_T("无法从串口读取<em>数据</em>!"));rn rn elsern rn if(dwLength!=0)rn rn OnCommRecv(pDlg, recvBuf, dwLength); rn rn rn rn rn delete[] recvBuf;rn return 0;rn
前台为什么接收不到数据
今天花了一上午,后台是证正常的,struts.xml是正常的 。但是就是说找<em>不到</em>这个方法。 最后发现是因为方法应该是public 但是手误成了private
axios数据php接收不到
axios发送异步 PHP<em>接收</em><em>不到</em>解决方案 发送异步<em>数据</em>格式不是Form Data Content-Type: application/x-www-form-urlencoded 解决办法: 引入qs库 https://github.com/ljharb/qs const qs = require('qs'); axios.post('/foo', qs.string...
SOCKET连接接收不到数据
现在手头有个项目要建立PHP(client)和JAVA(server)的SOCKET连接,传递<em>数据</em>:rnrn现在SOCKET连接建立是成功的,而且PHP发过来的测试<em>数据</em>,在SERVER端也是收的到的rnrn问题是SERVER发出的<em>数据</em>,在PHP<em>接收</em><em>不到</em>。请问各位有何看法啊?rnrn背景资料:rn1.SERVER端发送<em>数据</em>应该是成功的(不确定),因为并没有任何报错rn2.PHP老是出现这样的警告:rnWarning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in G:\AppServ\www\sock\index1.php on line 4rnrn第4行:if (! ($fd = fsockopen("192.168.0.103",8888,&$error_number,&$error_des,60)))rnrn3.PHP接受<em>数据</em>用的rnecho fgets($fd,100000);rnrn4. JAVA端发送<em>数据</em>是:rnOutputStream out = clientSocket.getOutputStream();rnPrintWriter out1 = new PrintWriter(out,true); rnout1.println("我是007");
UDP为什么接收不到数据?
我做了一个UDP程序,可是不能互传<em>数据</em>,请大家帮忙!rn服务器端:rn Public Sub exam2()rn ' This constructor arbitrarily assigns the local port number.rn Dim udpClient As New UdpClientrn Tryrn udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)rn Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Parse("192.168.30.51"), 13579)rn Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)rn Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)rn MessageBox.Show(("This is the message you received " + _rn returnData.ToString()))rn MessageBox.Show(("This message was sent from " + _rn RemoteIpEndPoint.Address.ToString() + _rn " on their port number " + _rn RemoteIpEndPoint.Port.ToString()))rn udpClient.Close()rn Catch e As Exceptionrn MessageBox.Show(e.ToString())rn End Tryrn End Subrn客户端:rn Dim udpClient As New UdpClientrn Tryrn udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)rn Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")rn udpClient.Send(sendBytes, sendBytes.Length)rn udpClient.Close()rn Catch e As Exceptionrn MessageBox.Show(e.ToString())rn End Tryrn请问错在哪了?
求助:为什么接收不到数据
我是新手,前几天跟着网上学写了一个VC++的ping程序,采用原始套接字收发<em>数据</em>,但我运行的时候,<em>数据</em>可以发送,但是<em>接收</em>的时候只有将本机设为目标地址才可以,当我ping了一下其他网站,程序就死了,我调试了几天了,也找不出哪里有问题,我快崩溃了,求助各位大虾指点指点,(我ICMP报文头和<em>数据</em>部分用校验和函数校验过没有问题)
MFC 串口通信 接收不到数据
程序之前写好了,运行没问题。但后来我重装了系统,所以要重新装了环境。导致现在的程序出现了问题,只能发送<em>数据</em>了,不能<em>接收</em><em>数据</em>(我从网上也下载了好几个写的代码,发现是同样的问题)。rn程序可以运行,但一旦<em>接收</em><em>数据</em>,调试栏就会有这样的异常[img=https://img-bbs.csdn.net/upload/201511/04/1446604050_979741.png][/img]rnDemo.exe 中的0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0030eb7c 处的 COleDispatchException。rnDemo.exe 中的0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x00000000 处的 [rethrow]。rn之后我只运行。发现这样的提示rnDemo.exe 中的0x753db9bc 处最可能的异常: 0x000006BA: RPC 服务器不可用。rnDemo.exe 中的0x753db9bc 处最可能的异常: 0x000006BA: RPC 服务器不可用。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039cd20 处的 nNIVISA_PXI_PLUGIN_DM_15_0::nNIPXITOOLS000::tIniFileIOException。rnDemo.exe 中的 0x753db9bc 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0039e1fc 处的 _com_error。rn这些都与0x753db9bc有关。
急!!!rs485 接收不到数据
RS485通信,带有RS232转485接口,用电脑的串口调试助手发送命令,在电脑上能看到有正确的<em>数据</em>返回,但是用FPGA发送同样的命令后,没有<em>数据</em>返回(FPGA的tx端有<em>数据</em>发送会亮绿灯,rx端有<em>数据</em>返回会亮红灯,发送端的<em>数据</em>接到电脑上看也是验证了正确的,但是就是没有<em>数据</em>返回,连红灯都不亮一下)求解啊!!用串口调试助手收发都没有问题,在FPGA的板上就不行了。。
xmlHttp接收不到数据,怎么回事?
function getLabelsGet() rn  xmlHttp=GetXmlHttpObject(); rn  if (xmlHttp==null) rn    alert('您的浏览器不支持AJAX!'); rn    return; rn   rn  var url="getstock.php?token="+token+"&key="+key+"&p1="+p1+"&p2="+p2; rnrn  xmlHttp.open("GET",url,true); rn  xmlHttp.onreadystatechange=getOkGet;//发送事件后,收到信息了调用函数 rn  xmlHttp.send(); rnrnfunction getStock() rn rn  xmlHttp=GetXmlHttpObject(); rn  if (xmlHttp==null) rn    alert('您的浏览器不支持AJAX!'); rn    return; rn   rn  var url="http://hq.sinajs.cn/list=sh601168"; rnrn  xmlHttp.open("GET",url,true); rn  xmlHttp.onreadystatechange=getStockOK;//发送事件后,收到信息了调用函数 rn  xmlHttp.send(); rnrnrnfunction getStockOK() rn rn  if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3) rn    // 本地提示:加载中 rn   rn if(xmlHttp.readyState==4)rnrn rn var data = xmlHttp.responseText;rn alert(data);rn rn rn  rn rngetStock();rnrn我打算取出字符串自己进行拆解,可是取<em>不到</em><em>数据</em>,该如何得到返回的字符串?并进行拆解呢?
用TWinSocketStream接收不到数据
ClientSocket用阻塞方式,thread中创建,rnTClientSocket *pClientSocket=new TClientSocket(NULL);rn pClientSocket->Address="127.0.0.1";rn pClientSocket->Port=7500;rn pClientSocket->ClientType=ctBlocking;rn rn pClientSocket->Active=true;rnrnvoid __fastcall socketthread::Execute()rnrn //---- Place thread code here ----rn TClientSocket *pClientSocket=new TClientSocket(NULL);rn pClientSocket->Address="127.0.0.1";rn pClientSocket->Port=7500;rn pClientSocket->ClientType=ctBlocking;rn pClientSocket->Socket->ClientType=ctBlocking;rn pClientSocket->Active=true;rnrnwhile(!Terminated)rnrn if(pClientSocket->Active)rn rn const int nBufferCount=2000;rn char cBuffer[nBufferCount];rn TWinSocketStream *pStream;rnrn tryrn rn pStream = new TWinSocketStream(pClientSocket->Socket, 4000);rnrn tryrn rnrn memset(cBuffer,0,nBufferCount);rn pStream->WaitForData(4000);rn //char quest[]="wait";rn //pStream->Write(quest.strlen(quest));rn int i=pStream->Read(cBuffer,strlen(cBuffer));rn Form1->Edit2->Text=AnsiString(cBuffer);rn rn rn catch (Exception &E)rn rn ::MessageBox(NULL,E.Message.c_str(),"eerr",MB_OK);rn rn rn __finallyrn rn delete pStream;rn rn rnrnrnrnrnServerSocket在ClientConnect事件中写rnvoid __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,rn TCustomWinSocket *Socket)rnrn Socket->SendText("ServerSocket1ClientConnectokok");rnrn但是接受<em>不到</em><em>数据</em>,不用thread,ClientSocket用非阻塞,在onread事件却可以独到,help me
C#串口通讯接收不到数据
rn我用C#写的串口通讯软件,串口通讯类用的是.Net的[color=#339966]SerialPort[/color]类。rn不知道为什么,同样的操作,[color=#FF00FF]有时候PDA发送的<em>数据</em>能够<em>接收</em>到,有时候<em>接收</em><em>不到</em>。[/color]rn而以前别人用Delphi写的串口通讯软件都能和PDA正常通讯。(和我现在做的这个功能一模一样,也是与PDA通讯)并且我们的串口参数:波特率等都设置的一样。
串口通讯:接收不到完整的数据
用mscomm串口控件,rn设置<em>接收</em>20个字节时,触发事件,rnrn但有事件触发,但收到的<em>数据</em>不足20个字节。rnrn用BusHound监控查看,发现,是分二段<em>数据</em>还回。。rnrn请问下,这种情况要怎么处理?rnrn:会提示:rn
vb.net 通信接收不到数据
那位可以帮我看下。下列代码第一次发送的时候可以<em>接收</em><em>数据</em>。再发就<em>接收</em><em>不到</em>的原因。 谢谢rnrn Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Clickrn If Button10.Text = "监听" Thenrn t = New Thread(AddressOf datareceive)rn t.Start()rn Button10.Text = "停止"rn listen.Enabled = Falsern Elsernrn listen.Enabled = Truern Button10.Text = "监听"rn 'c_socket1.Close()rn c_socket1.Close()rn t.Abort()rn End Ifrn End SubrnrnrnPublic Sub datareceive()rn Dim i As Integerrn 'Tryrnrn c_socket1 = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)rn Dim listenIpEndPoint As New IPEndPoint(IPAddress.Parse(myIp.ToString), Int(listen.Value.ToString.Trim))rn c_socket1.Bind(listenIpEndPoint)rn c_socket1.Listen(1028)rn While (True)rn Dim c_socket2 As Socket = c_socket1.Accept() '''''<em>接收</em>到的<em>数据</em>rnrn Dim returnData As String '''''<em>接收</em>到的<em>数据</em>(字符串型)rnrnrn Dim receiveBytes(2048) As Bytern i = c_socket2.Receive(receiveBytes)rn Dim datare(i - 1) As Bytern Array.Copy(receiveBytes, datare, i)rn '''''判断显示类型rnrn Select Case typeSelect.Text.Trimrnrn Case "ASCII值"rnrn returnData = Encoding.ASCII.GetString(datare)rnrn Case "ASCII码"rnrn returnData = byteToString(datare)rnrn Case "UNICODE"rnrn returnData = Encoding.Unicode.GetString(datare)rnrn Case Elsernrn returnData = byteToString(datare)rnrn End Selectrn '''''显示处理rn lbReceive.Items.Insert(0, returnData) '''''将其插入到列表框的第一项之前rn receiveCount.Text = receiveCount.Text + 1rn addSysInfo("<em>接收</em>到一条<em>数据</em>!")rn End Whilernrn 'Catch ex As Exceptionrn ' 'addSysInfo(SocketException.ErrorCode)rnrn 'End Tryrn End Subrnrn '---------------------------------------------------------rn ' 增加一条系统提示信息rn '---------------------------------------------------------rn Sub addSysInfo(ByVal str As String)rnrn Dim h As String = ""rnrn Dim m As String = ""rnrn Dim s As String = ""rnrn If Now.Hour < 10 Thenrnrn h = "0" & Now.Hourrnrn Elsernrn h = Now.Hourrnrn End Ifrnrn If Now.Minute < 10 Thenrnrn m = "0" & Now.Minuternrn Elsernrn m = Now.Minuternrn End Ifrnrn If Now.Second < 10 Thenrnrn s = "0" & Now.Secondrnrn Elsernrn s = Now.Secondrnrn End Ifrnrn str = "[ " & h & ":" & m & ":" & s & " ] " & strrnrn lbInfo.Items.Insert(0, str)rnrn End Sub
$.post回调函数接收不到数据
[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/2.gif][/img]是什么原因
C#串口通信 接收不到数据
[code=C#]rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.IO.Ports;rnrnrnnamespace GPSPortrnrn public partial class Form1 : Formrn rn private SerialPort comm = new SerialPort();rn private StringBuilder builder = new StringBuilder();rn private long Receive_count = 0, Send_count = 0;rnrn public Form1()rn rn InitializeComponent();rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn string[] ports = SerialPort.GetPortNames();rn Array.Sort(ports);rnrn PortName.Items.AddRange(ports);rn PortName.SelectedIndex = PortName.Items.Count > 0 ? 0 : -1;rn Baudrate.SelectedIndex = Baudrate.Items.IndexOf("9600");rnrn comm.NewLine = "\r\n";rn comm.RtsEnable = true;rnrn comm.DataReceived += comm_DataReceived;rn rn void comm_DataReceived(object sender,SerialDataReceivedEventArgs e)rn rn int n = comm.BytesToRead;rn byte[] buf=new byte[n];rn Receive_count += n;rn comm.Read(buf,0,n); rn string ReceiveText1;rn ReceiveText1 = builder.ToString();rn builder.Remove(0,builder.Length);rn label3.Text = "Get:" + Receive_count.ToString();rn this.Invoke((EventHandler)(delegatern rn builder.Append(Encoding.ASCII.GetString(buf));rn this.ReceiveText.AppendText(builder.ToString());rn ReceiveText1 = builder.ToString();rn string[] str =ReceiveText1.Split(',');rn foreach (string i in str) Arrtext.AppendText(i.ToString()+" ");rn ReceiveText.AppendText(ReceiveText1+"\n");rn ));rn rnrn private void button1_Click(object sender, EventArgs e)rn rn if (comm.IsOpen)rn rn comm.Close();rn rn elsern rn comm.PortName = PortName.Text;rn comm.BaudRate = int.Parse(Baudrate.Text);rn comm.ReadBufferSize = 4096;rn comm.WriteBufferSize = 4096;rn comm.DataBits = 8;rn comm.ReceivedBytesThreshold = 1024;rn tryrn rn comm.Open();rn rn catch (Exception ex)rn rn comm = new SerialPort();rn MessageBox.Show(ex.Message);rn rn rn button1.Text = comm.IsOpen ? "Close" : "Open";rn button2.Enabled = comm.IsOpen;rn rnrn private void button2_Click(object sender, EventArgs e)rn rn int n = 0;rn comm.Write(SendText.Text);rn n = SendText.Text.Length;rn Send_count+=n;rn label4.Text = "Set:" + Send_count.ToString();rn rn rnrnrn[/code]
RecvOneOrMore为什么接收不到数据
我测试socket的代码如下,发送一个长度为6字节,内容均为0的请求包,正常情况应该可以从服务器得到一个响应包,但是为什么这段代码<em>接收</em><em>不到</em><em>数据</em>,请高手赐教!谢谢rn[code=C/C++]void CTcpEngine::RunL()rn rn switch(iChannelState)rn rn case EChannelConnected:rn rn if (iStatus==KErrNone)rn rn // Connection was made successfullyrn iStatusText=_L("\nConnection established");rn NotifyProgress();rn rn rn TText8 pack[6] = 0, 0, 0, 0, 0, 0;rn iWriteDataBuffer.Append(pack, 6);rn rn iChannelState=EChannelSending;rn iSocket.Send(iWriteDataBuffer, 0, iStatus);rn SetActive();rn rn elsern rn iStatusText=_L("\nFailed to connect");rn NotifyProgress();rn rn rn break;rnrn case EChannelSending:rn rn // Receive data from the "server"rn iStatusText=_L("\nSent data");rn NotifyProgress();rnrn iSocket.RecvOneOrMore(iReadDataBuffer, 0, iStatus, iRecvLen);rn iChannelState=EChannelReceiving;rn SetActive();rn rn break;rnrn case EChannelReceiving:rn rn if (iStatus == KErrNone)rn rn // Data was received successfullyrn iStatusText=_L("\nReceived data");rn NotifyProgress();rn // Display received data in user interfacern //iStatusText=iReadDataBuffer;rn //NotifyProgress();rn rn elsern rn iStatusText=_L("\nError reading data");rn NotifyProgress();rn rnrn iStatusText=_L("\nClose the connection...");rn NotifyProgress();rnrn iSocket.Close();rn iStatusText=_L("\nEnd of test.");rn NotifyProgress();rn rn break;rn default:rn break;rn rn [/code]
我的Socket接收不到数据???
我写了一个多线程Socket服务端应用,Listen()后开线程处理,当一个客户端连接后,立即在线程里用Receive<em>接收</em>连<em>数据</em>,<em>接收</em>正常,rn 然后,这个连接不关闭,当Client端再发送<em>数据</em>的时候就收<em>不到</em>了,怎么办???
curl post接收不到数据
aa.php用curl函数向test.php POST<em>数据</em>rnrnaa.php内容:rn"aaa","pas"=>"bbbb");rn$ch = curl_init();rncurl_setopt($ch, CURLOPT_URL, "http://localhost/test.php");rncurl_setopt($ch, CURLOPT_POST, true);rncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);rncurl_setopt($ch, CURLOPT_POSTFIELDS, $data);rncurl_setopt($ch, CURLOPT_TIMEOUT, 30);rn$result = curl_exec($ch);rncurl_close($ch);rnecho $result;rn?> rnrntest.php内容:rn
ajax springmvc接收不到数据
后台 @RequestMapping(value = &quot;getAllChildByRId&quot;, method = RequestMethod.GET) public ModelAndView getAllChildByRId(String rId, Model model) { XLog.showLogInfo(&quot;rId = &quot; + rId); Model...
udp广播,接收不到数据??????
msdn上有一个udp广播的例子!rn大概这样rn发送广播: Dim addressa As IPAddress = IPAddress.Parse("224.0.0.1")rn Dim udp1 As New UdpClientrn udp1.Send(bytea, bytea.Length, ipport)rn udp1.Close()rn<em>接收</em>广播: Dim GroupAddress As IPAddress = IPAddress.Parse("224.0.0.1")rn Dim bytea() As Byte = udpa.Receive(ipport)rnrn我把代码运行后<em>接收</em><em>不到</em>!!!rn我感觉是广播地址添的有问题!!rn如果我的ip是192.168.100.129到192.168.100.144,子网是255.255.255.240rn我的广播地址应该如何添呢???为什摸??rnrn最后10分
shiro后端接收不到数据
1.出现后台接受<em>不到</em><em>数据</em> 也许是出了302 看了下以下文章    302定义 302 redirect: 302 代表暂时性转移(Temporarily Moved )。 意思就是你访问网址A,但是网址A因为服务器端的拦截器或者其他后端代码处理的原因,会被重定向到网址B。 解决方法 我这里出现302错误的原因是由于我的后端代码写了拦截器Filter,当从网站A访问带有某关键词路径的接口时...
C# 串口接收不到数据
我用串口调试助手可以<em>接收</em>到<em>数据</em>,但是用自己编写加修改人家代码得到的C#串口<em>接收</em><em>不到</em><em>数据</em>,请高手指教,我将代码贴出来rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rn//using System.Threading;rnusing System.Collections;rnusing System.Threading;rnusing System.IO.Ports; //--导入串口通讯所需命名空间,作用待定rnrnnamespace SerialPortrnrn public partial class Serial : Formrn rn public Serial()rn rn InitializeComponent();rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn try //--使用try catch防止串口获取出现错误rn rn string[] szPorts = System.IO.Ports.SerialPort.GetPortNames(); //--获取当前PC机接入串口rn combSerialPort.Items.AddRange(szPorts); //--rn combSerialPort.SelectedIndex = 0;rn rn catch (Win32Exception win32ex) //获取串口出错rn rn MessageBox.Show(win32ex.ToString());rn rn //--串口相关参数初始化rn //--波特率rn serialPort1.PortName = combSerialPort.Text;rn string[] ss = new string[] "9600", "19200", "57600", "115200" ;rn combBaudRate.DataSource = ss;rnrn //--校验位rn combParityBit.DataSource = Enum.GetNames(typeof(Parity));rnrn //--<em>数据</em>位rn ss = new string[] "5", "6", "7", "8" ;rn combDataBit.DataSource = ss;rn combDataBit.Text = "8";rnrn //--停止位rn combStopBits.DataSource = Enum.GetNames(typeof(StopBits));rn combStopBits.Text = Enum.Format(typeof(StopBits), StopBits.One, "G");rn serialPort1.Encoding = Encoding.GetEncoding("gb2312");//<em>接收</em>发送转换编码rn rnrn private void btnOpenCom_Click(object sender, EventArgs e)rn rn tryrn rn if (serialPort1.IsOpen)rn rn serialPort1.Close();rn rn elsern rn serialPort1.PortName = combSerialPort.Text;rn serialPort1.BaudRate = Convert.ToInt32(combBaudRate.Text);rn serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), combParityBit.Text);rn serialPort1.DataBits = Int32.Parse(combDataBit.Text);rn serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), combStopBits.Text);rn serialPort1.Encoding = Encoding.GetEncoding("Gb2312");rn serialPort1.Open();rn rn RefrespictureBox1();rn //--串口信息显示rn toolStripStatusLabel1.Text = "串口:" + combSerialPort.SelectedItem.ToString() rn + " 波特率:" + combBaudRate.SelectedItem.ToString() rn + " <em>数据</em>位:"+combParityBit.SelectedItem.ToString()rn + " 停止位:" + combStopBits.SelectedItem.ToString(); //--综合显示信息rn textBox1.Text =DateTime.Now.ToString();rnrn rn catch (Exception)rn rn rnrn public void RefrespictureBox1()rn rn if (serialPort1.IsOpen)rn rn btnOpenCom.BackColor = SystemColors.GradientActiveCaption;rn btnOpenCom.Text = "关闭";rn rn elsern rn btnOpenCom.BackColor = SystemColors.Control;rn btnOpenCom.Text = "打开";rn rn rnrn private void btnSendData_Click(object sender, EventArgs e)rn rn tryrn rn string s = "";rn if (checkBox1.Checked) //--16进制发送rn rn ArrayList al = MyClass.Str16ToArrayList(editSendData.Text); //--MyClass是自定义的一个类rn //--转化后<em>数据</em>rn byte[] by = new byte[al.Count];rn int i = 0;rn foreach (string stmp in al)rn rn by[i] += Convert.ToByte(stmp, 16);rn i++;rn rn s = Encoding.GetEncoding("Gb2312").GetString(by); rn rn else rn rn s = editSendData.Text;rn rn serialPort1.Write(s); //--串口发送rn rn catch (Exception)rn rn rnrnrnrn //--**************多线程操作!*********************--//rn delegate void SetTextCallback(string text);rn private void SetText(string text)rn rn tryrn rn //--获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,rn //--因为调用方位于创建控件所在的线程以外的线程中,主要判断是否是调用方位于创建控件所在的线程以外的线程中rn if (this.editRecvData.InvokeRequired)rn rn SetTextCallback d = new SetTextCallback(SetText);//--使用委托。rn this.Invoke(d, new object[] text ); //--在拥有此控件的基础窗口句柄的线程上执行指定的委托rn rn elsern rn this.editRecvData.Text += text; //--同一线程时修改属性值rn rn rn catch (Exception)rn rn rn rnrn //--backgroundWorker1_DoWorkrn private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)rn rn char[] c;rn while (true)rn rn tryrn rn if (serialPort1.IsOpen)rn rn c = new char[serialPort1.BytesToRead]; rn serialPort1.Read(c, 0, c.Length); rn if (c.Length > 0)rn rn if (checkBox2.Checked)rn rn byte[] by = Encoding.GetEncoding("Gb2312").GetBytes(c);rn foreach (byte btmp in by)rn rn string s = "00" + string.Format("0:X", btmp);rn s = s.Substring(s.Length - 2, 2);rn SetText(new string(s.ToCharArray()));rn SetText(" ");rn rn rn elsern rn SetText(new string(c));rn rn rn rn rn catch (Exception) rn Thread.Sleep(1);rn rn rnrn private void checkBox1_CheckedChanged(object sender, EventArgs e)rn rn string s = "";rn if (checkBox1.CheckState == CheckState.Checked)rn rn byte[] by = Encoding.GetEncoding("Gb2312").GetBytes(editSendData.Text);rn editSendData.Text = "";rn foreach (byte btmp in by)rn rn s = "00" + string.Format("0:X", btmp);rn editSendData.Text += s.Substring(s.Length - 2, 2);rn editSendData.Text += " ";rn rn rn elsern rn ArrayList al = MyClass.Str16ToArrayList(editSendData.Text);rn byte[] by = new byte[al.Count];rn int i = 0;rn foreach (string stmp in al)rn rn by[i] += Convert.ToByte(stmp, 16);rn i++;rn rn editSendData.Text = Encoding.GetEncoding("Gb2312").GetString(by);rn rn rn rn //--默认关闭界面保存<em>数据</em>rn private void Form1_FormClosed(object sender, FormClosedEventArgs e)rn rn Properties.Settings.Default.Save();rn rnrn private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)rn rn editRecvData.Text = "";rn rn //--------**********************-------//rn private void editSendData_KeyPress(object sender, KeyPressEventArgs e)rn rn if (checkBox1.CheckState == CheckState.Checked)rn rn if (!Uri.IsHexDigit(e.KeyChar) && e.KeyChar != ' ')rn rn e.KeyChar = (char)0;rn rn rn rnrn rnrn
TIdUDPServer 的 onread接收不到数据
COM+的中TIdUDPServer 的 onread<em>接收</em><em>不到</em><em>数据</em>,郁闷
BeginReceiveFrom 接收不到数据 C#
我写了一个简单的发送接受程序 用的是UDP无连接异步传输.一个窗体里就包含了 接受和发送的控件.rnpublic Socket udpS rnpublic Socket udpRrnbyte[] sendByteBufferrnbyte[] recvByteBufferrn是全局变量.rnForm1_Load()里:rnudpR rnudpS都绑定为"本地主机IP:0"rnrecvep 是 "0.0.0.0:0"rnudpS.BeginReceiveFrom(recvByteBuffer, 0, recvByteBuffer.Length, SocketFlags.None, ref recvep, new AsyncCallback(ReceiveCallback), udpS);rnReceiveCallback函数是:rn private void ReceiveCallback(IAsyncResult ar)rn rn MessageBox.Show("Receive message!");rn Socket result = (Socket)ar.AsyncState;rnrn IPEndPoint exp = new IPEndPoint(IPAddress.Any, 0);rn EndPoint recvep = (EndPoint)exp;rn int recv = 0;rn tryrn rn //(1) 0)rn rn textBox2.Text += Encoding.BigEndianUnicode.GetString(recvByteBuffer, 0, recv );rnrn Array.Clear(recvByteBuffer, 0, recvByteBuffer.Length);rnrn result.BeginReceiveFrom(recvByteBuffer, 0, recvByteBuffer.Length, SocketFlags.None, ref recvep, new AsyncCallback(ReceiveCallback), result);rn rn elsern rn MessageBox.Show("end");rn result.Close();rn rn rnrn发送端:rn用过udpS.BeginSendTo 也用过 udpS.SendTo rnrn问题是,我如果全部都用一个Socket对象,比如说全部用udpS 会在(1)的地方出现"远程主机强迫关闭了一个现有的连接"的异常.导致接受<em>不到</em><em>数据</em>.rn如果我用udpS 发送<em>数据</em>udpR 接受 那么连回调函数都进不去,就是说,根本连进ReceiveCallback调试的机会也没有.rn我不知道问题出在哪里,哪位大哥帮忙看看啊,到底是哪里错了,是我的IP绑的有问题,还是哪个地方写错了.
vb mscomm 接收不到数据
[code=vb][/code]rnPrivate Sub Form_Load()rn Dim i As Integerrn If MSComm1.PortOpen = True Thenrn MSComm1.PortOpen = Falsern End If '先判断串口是否关闭,如果打开则关闭rn MSComm1.CommPort = 5 'COM端口rn MSComm1.Settings = "115200,n,8,1"rn MSComm1.InputLen = 0 '读取<em>接收</em>缓冲区的所有字符rn MSComm1.InputMode = comInputModeBinary '采用二进制传输rn MSComm1.InBufferSize = 1024 '接受缓冲区为1024字节rn MSComm1.OutBufferSize = 2048 '发送缓冲区位2048字节rn MSComm1.InBufferCount = 0 '清空接受缓冲区rn MSComm1.OutBufferCount = 0 '清空传输缓冲区rn MSComm1.SThreshold = 0 '禁止发送事件rn MSComm1.RThreshold = 1 '产生MSComm事件rn Command2.Enabled = False '初始化时设置“关闭”按钮不可用 rnEnd SubrnrnPrivate Sub MSComm1_OnComm()rnrn Dim inbyte() As Byte '存储<em>接收</em>串口<em>数据</em>rn Dim buffer As String '存储处理后的串口<em>数据</em>rn Dim lenbuffer As Integer '存储处理后的串口<em>数据</em>长度rn Dim i As Integer '设置循环变量rn rn Select Case MSComm1.CommEventrn Case comEvReceivern inbyte = MSComm1.Input rn For i = LBound(inbyte) To UBound(inbyte)rn rn If Len(Hex(inbyte(i))) = 1 Thenrn buffer = buffer + "0" + Hex(inbyte(i)) + Chr(32)rn Elsern buffer = buffer + Hex(inbyte(i)) + Chr(32)rn End If rnrn lenbuffer = Len(Replace(Trim(buffer), " ", ""))rnrn Select Case lenbufferrn Case Is = 14rn If CByte("&H" & (Mid(Replace(buffer, " ", ""), 1, 2))) = &HAA _rn And "&H" & (Mid(Replace(buffer, " ", ""), 14 - 4 + 1, 2)) = &H42 _rn And "&H" & (Mid(Replace(buffer, " ", ""), 14 - 2 + 1, 2)) = &H42 Then rn If "&H" & (Mid(Replace(buffer, " ", ""), 14 - 12 + 1, 2)) = &H55 Then rn rn If "&H" & (Mid(Replace(buffer, " ", ""), 14 - 10 + 1, 2)) = &H43 _rn And "&H" & (Mid(Replace(buffer, " ", ""), 14 - 8 + 1, 2)) = &H47 _rn And "&H" & (Mid(Replace(buffer, " ", ""), 14 - 6 + 1, 2)) = &H8A Thenrn Text2.Text = "测试通过"rn End If rn rn End Ifrn End Ifrnrn case is = 18rn ....... 省略rnrn End Selectrn Next irn End Subrnrnrn想问下,为什么上位机<em>接收</em><em>不到</em><em>数据</em>???
为什么MSComm接收不到数据
MScom->InputMode = comInputModeBinary;rnMScom->RTreshold = 1;rn一点反应都没有rn还有一点就是怎样把字符串转化成二进制发送出去,谢谢!
linux下,服务器程序接收不到数据
服务器程序很简单,就是一个udp的<em>接收</em>程序,我在虚拟机上试过,可以<em>接收</em><em>数据</em>,但放在外网的服务器上<em>接收</em><em>不到</em>,本地电脑可以ping到外网服务器,我是用普通用户运行服务器程序的,是不是跟用户权限有关啊?
win2003超级终端接收不到数据
win2003系统,用超级终端电话线拨号连接一台XP习题计算机,win2003可以发送<em>数据</em>文件,但<em>接收</em><em>不到</em><em>数据</em>
接收不到CAN发送的数据
我使用RL78/F13 R5F10BLGKFB 进行CAN<em>数据</em>传输,CAN相关的代码是通过RS-CAN configurator生成的,将这些文件导入CS+工程中,并进行设置后,开始进行CAN <em>数据</em>发送,但是发送不出去。rnrn通过调试,我发现<em>数据</em>写入到了相应的CAN <em>数据</em>传输寄存器,但是进行发送请求后,相应的发送请求位一直为1[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/19.gif][/img],示波器也测不出波形,实在是找不出哪里出问题了。望各位大侠、大佬指点迷津、不吝赐教,不胜感激!!![img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/2.gif][/img]
recvfrom接收数据包超时问题
实现路由跟踪,前面几跳<em>recvfrom</em>都返回超时错误,但是我用抓包工具查了下,能收到路由器发过来的icmp包。只有最后一跳(到达目的地)能<em>接收</em>到icmp<em>数据</em>包。怎么改啊?rnrnm_sockRaw = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, rn NULL, 0,WSA_FLAG_OVERLAPPED); rn……rnsendto(m_sockRaw, m_IcmpData, m_nDatasize, 0, rn (SOCKADDR *)&m_addrDest, sizeof(m_addrDest));rn<em>recvfrom</em>(m_sockRaw, m_RcvBuffer, MAX_PACKET, 0, rn (struct sockaddr*)&m_addrFrom, &fromlen); rnrn我下了好几个别人写的代码也出现这样的问题,是怎么回事啊?rn我抓包的时候能抓到路由器发过来的icmp包。rnrn网络编程新手,求高手指点。
recvfrom接收消息函数详解
课程概述rn rnrn 这部教程是windows网络编程课程的第二部分课程:基于udp/ip协议的网络模型 rnrnrn 网络编程是互联基石,是程序猿基础必备技能,咱们这部UDP/IP课程为大家介绍有关于UDP/IP基本理论知识的分析,以及5个常用的网络模型,课程以代码实践为主,理论分析为辅,希望能帮助到大家。 rnrnrn课程特点:rn课程代码会带大家一行一行书写,保证大家都能够学会。rnrnrn rnrnrn rnrn
服务程序 recvfrom不到数据
int Error; rn SOCKET socket1; rn WORD VersionRequested; rn WSADATA WsaData; rn VersionRequested=MAKEWORD(2,2); rn Error=WSAStartup(VersionRequested,&WsaData); //启动WinSock2 rn char szError[256];rn DWORD dwError = GetLastError();rn FormatMessage(rn FORMAT_MESSAGE_FROM_SYSTEM,rn NULL,rn dwError,rn 0,rn szError,rn sizeof(szError),rn NULL);rn ::MessageBox(NULL,szError,"",0);rnrnrn struct sockaddr_in local; rn struct sockaddr_in from; rn int fromlen =sizeof(from); rn local.sin_family=AF_INET; rn local.sin_port=htons(8000); ///监听端口 rn local.sin_addr.s_addr=htonl(INADDR_ANY); ///本机 rn rn socket1=socket(AF_INET,SOCK_DGRAM,0); rn rn bind(socket1,(struct sockaddr*)&local,sizeof local); rn dwError = GetLastError();rn FormatMessage(rn FORMAT_MESSAGE_FROM_SYSTEM,rn NULL,rn dwError,rn 0,rn szError,rn sizeof(szError),rn NULL);rn ::MessageBox(NULL,szError,"",0);rn while (1) rn rn char buffer[1024]= "\0 "; rn //printf( "waiting for message from others-------------\n "); rn int rr=<em>recvfrom</em>(socket1,buffer,sizeof buffer,0,NULL,NULL)!=SOCKET_ERROR; rn //MessageBox(NULL,"","",0);rn FILE *file1; rn file1=fopen( "c:\\Client.txt ", "a+ "); rn fwrite(buffer,sizeof(char)*1024,rr,file1); rn fclose(file1); rn rn Sleep(500); rn rn rn closesocket(socket1); rnrn在服务程序中到int rr=<em>recvfrom</em>(socket1,buffer,sizeof buffer,0,NULL,NULL)!=SOCKET_ERROR; rn就阻塞在那里,设置为非阻塞方式,返回为“无法立即完成一个非阻挡性套接字操作”,将这段代码放在一般程序中执行很好!rn计算机一直在接受<em>数据</em>。。rnrn这到底是怎么回事儿呢????rn
recvfrom接受客户端数据
C++socket网络编程大全实战http服务器(支持php)视频培训教程概况:本课程会同时演示在linux和windows中的编程,课程中的线程和正则表达式都使用c++提供库。本课程包含了socket网络编程常用的所有特性,包括tcp、udp协议的基础编程,广播包,超时连接,多路复用,高并发的epoll多路复用,多线程的服务端。课程讲解理论与实践相结合,实践以代码延时讲解为主。
求助,recvfrom不到数据
不知道为什么一直卡在<em>recvfrom</em>里面,请各位高手指教,不胜感激!!rnrnserver:rnrn#include rn#include rn#include rn#include rn#include rn#include rn#include rnrn#define MSG_SIZE 1024rnrnint main(int argc,char *argv[])rnrn puts("Udp Server");rn int sockfd,addrlen,n,flag=1;rn char buf[MSG_SIZE];rn struct sockaddr_in addr,addr_in;rn rn sockfd=socket(AF_INET,SOCK_DGRAM,0);rn if(sockfd0)rn rn printf("From client %s\n",buf);rn bzero(buf,sizeof(buf));rn gets(buf);rn sendto(sockfd,buf,strlen(buf),0,(struct sockaddr *)&addr_in,addrlen);rn rn elsern rn perror("recv failed");rn exit(1);rn rn rn close(sockfd);rn rnrnrnclient:rnrn#include rn#include rn#include rn#include rn#include rn#include rn#include rnrn#define MSG_SIZE 1024rnrnint main(int argc,char *argv[])rnrn puts("Udp Client");rn int sockfd,addrlen,n,flag=1;rn char buf[MSG_SIZE];rn struct sockaddr_in addr;rn rn sockfd=socket(AF_INET,SOCK_DGRAM,0);rn if(sockfd0)rn rn printf("From server %s\n",buf);rn if(strcmp(buf,"finish")==0)rn rn puts("ok,is over");rn break;rn rn bzero(buf,sizeof(buf));rn rn elsern rn perror("recv failed");rn exit(1);rn rn rn close(sockfd);rn rnrnrn用gdb看client已经正确发出去了,但服务器就是收<em>不到</em>,郁闷。。rn
ICMP编程问题!!recvfrom接收不到数据!!!急急急急急急急急急急急急!!
#pragma comment(lib,"ws2_32.lib")rnrn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn using namespace std;rnrntypedef struct iphdrrn unsigned char ver_hlen;rn unsigned char tos;rn unsigned short total_len;rn unsigned short ident;rn unsigned short frag_and_flags;rn unsigned char ttl;rn unsigned char proto;rn unsigned short checksum;rn unsigned int sourceIP;rn unsigned int destIP;rnIPHeader;rnrntypedef struct icmphdrrnrn unsigned char type;rn unsigned char code;rn unsigned short cksum;rn unsigned short id;rn unsigned short seq;rnICMPHeader;rn发送端:rn#include "Server1.h"rn#include rn#include rn#include rn#include rn#include rn#define ICMP_ECHO_REPLY 0rn#define ICMP_ECHO_REQUEST 8rn#define PACKAGE_SIZE sizeof(IPHeader)+sizeof(ICMPHeader)+128rn#define destip "127.0.0.1"rn#include rn#include rn#include rn using namespace std;rnrnrn#define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s)) rn#define xfree(p) HeapFree(GetProcessHeap(),0,(p))rnrnvoid HandlenError(char *func);rnrnvoid FillPackage(char* pData,unsigned long,u_short id); rnu_short CheckSum(u_short *,int);rnrnvoid main()rnrn SOCKET sock;rn int pid=_getpid();//得到一个进程号rn unsigned long dstIP;rn dstIP=inet_addr(destip);rn WSAData wsaData;rnrn WSAStartup(WINSOCK_VERSION,&wsaData);rnrn sock=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);rn if(sock==SOCKET_ERROR)rn rn printf("socket failed!");rn rn rn struct sockaddr_in to;rn memset(&to,0,sizeof(to));rn to.sin_addr.s_addr=dstIP;rn to.sin_family=AF_INET;rn int len=sizeof(to);rn char* buf=(char *)xmalloc(PACKAGE_SIZE);rn while(1)rn rn FillPackage(buf,dstIP,(u_short) pid);rn Sleep(1000);rn sendto(sock,buf,PACKAGE_SIZE,0,(struct sockaddr *)&to,len);rn if(sendto(sock,buf,PACKAGE_SIZE,0,(struct sockaddr *)&to,len))rn rn printf("ok\n");rn rn rn rn xfree(buf);rn closesocket(sock);rn WSACleanup();rnrnvoid FillPackage(char* pData,unsigned long destIP,u_short id)rnrn int n;rn char hostname[256];rn static sockaddr_in sa;rn hostent *Host;rn gethostname(hostname,sizeof(hostname)); rn Host=gethostbyname(hostname);rn for(n=0;Host->h_addr_list[n];n++)rn rn memcpy(&sa.sin_addr.s_addr,Host->h_addr_list[n],Host->h_length);rn rn memset(pData,0,PACKAGE_SIZE);rn rn int nVersion=4;rn int nHeadSize=sizeof(IPHeader);rn unsigned long srcIP=sa.sin_addr.s_addr;rn unsigned long deIP=destIP;rnrn IPHeader *pIPHeader=(IPHeader *) pData;rn pIPHeader->ver_hlen=(nVersiontotal_len=htons(PACKAGE_SIZE);rn pIPHeader->ident=htons(1234);rn pIPHeader->frag_and_flags=0;rn pIPHeader->ttl=255;rn pIPHeader->proto=IPPROTO_ICMP;rn pIPHeader->checksum=0;rn pIPHeader->sourceIP=srcIP;rn pIPHeader->destIP=deIP;rn pIPHeader->checksum=CheckSum((USHORT *) pData,sizeof(IPHeader));rnrn ICMPHeader *pICMPHeader=(ICMPHeader *)(pData+sizeof(IPHeader));rn pICMPHeader->type=ICMP_ECHO_REQUEST;rn pICMPHeader->code=0;rn pICMPHeader->id=htons(id);rn pICMPHeader->seq=htons(id);rn pICMPHeader->cksum=CheckSum((USHORT *)((char *)pData+sizeof(IPHeader)),sizeof(ICMPHeader));rn rn char *icmp_data;rn icmp_data=pData;rn memset(icmp_data,0,PACKAGE_SIZE-(sizeof(IPHeader)+sizeof(ICMPHeader)));rnrnrnUSHORT CheckSum(USHORT *pUShort,int size)rnrn unsigned long cksum=0;rn while(size>1)rn rn cksum += *pUShort++;rn size-=sizeof(USHORT);rnrn rn if(size)rn rn cksum+=*(UCHAR *)pUShort;rnrn rnrn cksum=(cksum>>16)+(cksum & 0xffff);rn cksum+=(cksum>>16);rn return (USHORT)(~cksum);rnrnvoid HandlenError(char *func)rnrnrn int errCode=WSAGetLastError();rn char info[65]=0;rn _snprintf(info,64,"%s: %d\n",func,errCode);rn printf(info);rnrn<em>接收</em>端:rn#include "client.h"rn#include rn#include rn#include rn#include rn#include rn#define ICMP_ECHO_REPLY 0rn#define ICMP_ECHO_REQUEST 8rn#define PACKAGE_SIZE sizeof(IPHeader)+sizeof(ICMPHeader)+128rn#include rn#include rn#include rn using namespace std;rnrn#define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s)) rn#define xfree(p) HeapFree(GetProcessHeap(),0,(p))rnrn void main()rnrnrn SOCKET sock;rn WSAData wsaData; rn WSAStartup(WINSOCK_VERSION,&wsaData);rn sock=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);rn if(sock==SOCKET_ERROR)rn rn printf("socket failed!");rn rn rn struct sockaddr_in from;rn int len=sizeof(from);rn// char* buf=(char *)xmalloc(PACKAGE_SIZE);rn char buf[PACKAGE_SIZE];rn// memset(buf,0,PACKAGE_SIZE);rn memset(&from,0,sizeof(from));rn from.sin_addr.s_addr=INADDR_ANY;rn from.sin_family=AF_INET;rn from.sin_port=htons(999);rnrn bind(sock,(struct sockaddr *)&from,len);rnrn while(1)rn rn Sleep(1000);rn if(<em>recvfrom</em>(sock,buf,PACKAGE_SIZE,0,(struct sockaddr *)&from,&len))rn rn printf("ok\n");rn rnrn IPHeader *pIPHdr=(IPHeader *)buf;rn ICMPHeader *pICMPHdr=(ICMPHeader *)(buf+sizeof(IPHeader));rn printf("%s\n",inet_ntoa(from.sin_addr));rn rn rn xfree(buf);rn closesocket(sock);rn WSACleanup();rnrn<em>接收</em>端<em>接收</em><em>不到</em>任何东西!!一直处于<em>接收</em>状态!!rn是什么问题???rn希望大家快点帮我解决!!谢谢!!!
servlet接收不到JSP传来的数据servlet接收不到JSP传来的数据
就是一个很简单的程序 JSP输入用户名,在servlet接受后显示出来,但是每次显示的都是null JSP页面: java" import="java.util.*" %>        ">                         账号:   密码:       servlet代码如下: import java.io.IO
关于UDP通信中的recvfrom数据接收问题
我想要完成这样的功能:对DNSserver进行域名查询,即我自己封装一个DNS<em>数据</em>包,以UDP的方式发给DNS服务器,然后再用<em>recvfrom</em>函数来接受DNS服务器的应答包,对收到的<em>数据</em>包进行解析,但是不知道怎么回事,DNS请求包发出去了,但是<em>recvfrom</em>总是收<em>不到</em>应答,以下是源代码,请大家帮忙看看rn#include rn#include rn#include rn#include rn rntypedef struct _DNSHEAD //dns 头部 rn USHORT ID; rn USHORT tag; // dns 标志(参数) rn USHORT numQ; // 问题数 rn USHORT numA; // 答案数 rn USHORT numA1; // 权威答案数 rn USHORT numA2; // 附加答案数 rnDnsHead; rntypedef struct _DNSQUERY //dns 查询结构 rn rn// char name[64]; rn// //查询的域名,这是一个大小在0到63之间的字符串; rn USHORT type; rn //查询类型,大约有20个不同的类型 rn USHORT classes; rn //查询类,通常是A类既查询IP地址。 rn rnDnsQuery; rn rn#pragma comment(lib,"ws2_32.lib") rn rn// 初始化操作 rnbool initWSA(); rn rn//显示错误 rnvoid displayErrWSA(char *str); rn rn//创建套接字 rnSOCKET CreateSocket(int type); rn rn//UDP sendto rnint MySendto(SOCKET sockTo, const char FAR * buf,int len,char *addr,USHORT port); rn rn//TCP 连接 rnbool MyConnect(SOCKET s, char *addr,USHORT ); rn rn// UDP <em>recvfrom</em> rnint MyRecvFrom(SOCKET s, char FAR * buf,int len,char *addr,USHORT port); rn rn//设置DNS 头部 rnbool SetDNSHead(char *name,char *buf); rn rnint main(int arg,char *are[]) rn rn int Result=0; rn char buf[1024]=0; rn char addr[16] = "61.187.72.8";// dns 服务器地址 rn char *name = 0; //要查询的域名 rn rn if ( !initWSA() )//初始化 rn rn displayErrWSA("initWSA err!"); rn return 1; rn rn rn //创建套接字 rn SOCKET sockTo ; rn if ( (sockTo = CreateSocket(SOCK_DGRAM)) == 0) rn rn displayErrWSA("CreatSocket err!"); rn return 1; rn rn while (1) rn rn if (arg < 2) rn rn char temp[1024]=0; rn printf("\n请输入要查询的域名:"); rn scanf("%s",temp); rn if (temp[0] == 'q' ||temp[0] == 'Q') rn rn break; rn rn name = temp; rn rn else rn rn arg = 1; rn name = are[1]; rn rn rn //设置dns 头部 rn SetDNSHead(name,buf); rn rn //发送出去的请求<em>数据</em>长度 rn int len = sizeof(DnsHead)+sizeof(DnsQuery)+strlen(name)+2; rn rn// for (int i =0;inumA == 0) rn rn printf("无法解析 %s 的IP 地址。\n",name); rn continue; rn rn char *getIP =(char *)buf +Result - 4; rn printf("%s 的IP地址为: ",name); rn for (int Result= 0 ;ResultID = (USHORT)1; rn DnsH->tag = htons(0x0100); rn DnsH->numQ = htons(1); rn DnsH->numA = 0; rn rn DnsQuery *DnsQ =(DnsQuery *) ( buf+ sizeof(DnsHead) ); rn int NameLen = ChName(name,(char *)DnsQ); rn rn //设置查询信息 rn DnsQ = (DnsQuery *)( (char *)DnsQ + NameLen ); rn DnsQ->classes = htons(1); rn DnsQ->type = htons(1); rn return true; rn rn rn rn rn//显示错误信息 rnvoid displayErrWSA(char *str) rn rn printf("\n%s,err = %d\n",str,WSAGetLastError()); rn getchar(); rn rn rn rn//域名转化 rnint ChName(char *fname,char *tname) rn rn rn int j =0; rn int i =strlen(fname)-1; rn tname[i+2] = 0; rn int k = i+1; rn for (; i>=0;i--,k--) rn rn if (fname[i] == '.') rn rn tname[k] = j; rn j=0; rn rn else rn rn tname[k] = fname[i]; rn j++; rn rn rn tname[k] = j; rn return strlen(tname)+1; rn
json数据在前台接收不到数据的解决方法
在学习SSH项目商城的时候,通过查询<em>数据</em>库的<em>数据</em>,并将<em>数据</em>打包成json格式并在前台显示时出现了 Struts has detected an unhandled exception: Messages:failed to lazily initialize a collection of role: cn.it.shop.model.Account.categories, could not
网络编程新人提问:为什么接收不到数据???
我用的mfc实现telnet,程序大体是:rn[code=C/C++]void CTelnetDoc::ConnectToHost(CString m_strHost, UINT m_nPort)rnrn BOOL bOK;rn rn m_sClient = new CClientSocket(this);rn if(m_sClient != NULL)rn rn bOK = m_sClient->Create();rn if(bOK == TRUE)rn rn m_sClient->AsyncSelect(FD_READ | FD_WRITE | FD_CLOSE | FD_CONNECT | FD_OOB);rn m_sClient->Connect(m_strHost, m_nPort);rn //int error = GetLastError();//〖10035〗-无法立即完成一个非阻挡性套接字操作rn rnrn elsern rn delete m_sClient;rn rn rnrn elsern rn AfxMessageBox("Could not create new socket",MB_OK);rn rnrnrnrn之后在OnReceive里调用rnvoid CTelnetDoc::ProcessMessage(CClientSocket *cSocket)rnrn int nBytes = cSocket->Receive(m_bBuf.GetData(),m_bBuf.GetSize() );rnrn if(nBytes != SOCKET_ERROR)rn rn int ndx = 0;rn while(GetLine(m_bBuf, nBytes, ndx) != TRUE);rnrn ProcessOptions();rn ( (CTelnetView*)m_viewList.GetHead() )->Message(m_strNormalText);rn rn m_strLine.Empty();rn m_strResp.Empty();rnrnrnrn TempCounter++;rn[/code]rn结果是nBytes为0,收<em>不到</em>任何信息 程序就进入while(GetLine(m_bBuf, nBytes, ndx) != TRUE);的死循环中rnrn求大牛帮助!!!
怎么办啊 ?接收不到数据。。。。。。。。。。。通信。。。。
BOOL DSGetNextData(DtuDataStruct* pDataStruct,u16t waitseconds)rn功能:读取下一条Dtu送上来的信息rn参数:pDataStruct: 存放Dtu所送上来的信息和<em>数据</em>的结构,读函数执行成功后,返回的<em>数据</em>存放到该参数指向的结构中rnwaitseconds:本函数读到<em>数据</em>后立即返回;如果没有<em>数据</em>到达,则等待最长waitseconds(时间单位:秒)的时间,直到有<em>数据</em>到达,取值范围从0~65535,如果取值为0表明本函数将立即返回。另外,当在另一个线程中执行成功了DSStopService()后,本函数将立即返回。rn返回:如果返回为非零值,表明收到了一条Dtu信息。如果返回为0,则表明没有收到<em>数据</em>。rnrnrn上面是gprs_dtu<em>数据</em><em>接收</em>函数,我设定每5秒执行一次,为什么每次都读<em>不到</em><em>数据</em>呢?有谁做过这方面,给点意见啊。rnrn听人说,可能是啥维系连接,注册包之类的问题 ,不懂啊
CSocket 中的receive接收不到数据
rnvoid Time::Receivedata()rn rn char buffer[1024];rn memset (buffer,'\0',sizeof(buffer));//数组初始化rnrn int Recv=pSocket.Receive(buffer,2,0);rn if(Recv>0)rn rn m_data=buffer;rnrn AfxMessageBox(m_data);rn rn elsern rn AfxMessageBox("没有<em>数据</em>!");rn rnrnpsocket是 Client psocket;Client继承CSocketrnrn运行后显示没有<em>数据</em>。
servlet接收不到JSP传来的数据
就是一个很简单的程序 JSP输入用户名,在servlet接受后显示出来,但是每次显示的都是null,大家帮我看一下。。rnrnJSP页面:rnrnrn rnrnrnrnrn rn rn rn rn rn rn rn rn rn 账号: rn 密码: rn rn rn rnrnrnrnservlet代码如下:rnimport java.io.IOException;rnimport java.io.PrintWriter;rnrnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnrnpublic class aa extends HttpServlet rnrn public aa() rn super();rn rnrn public void destroy() rn super.destroy(); // Just puts "destroy" string in logrn // Put your code herern rnrn public void doGet(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOException rnrn response.setContentType("text/html");rn PrintWriter out = response.getWriter();rn rn String AdmName = request.getParameter("AdmName");rn String AdmPassword = request.getParameter("AdmPassword");rn rn out.println(AdmName);rn out.flush();rn out.close();rn rnrnrn public void doPost(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOException rnrn response.setContentType("text/html");rn PrintWriter out = response.getWriter();rn rn out.flush();rn out.close();rn rnrn public void init() throws ServletException rn rn rnrnrnrn
为什么VB接收不到串口来的数据
Private Sub Form_Load()rnIf MSComm1.PortOpen = False Thenrn MSComm1.PortOpen = TruernEnd IfrnText1.Text = ""rnEnd SubrnrnPrivate Sub MSComm1_OnComm()rnSelect Case MSComm1.CommEventrnCase comEvReceive '...有<em>接收</em>事件发生rnText1.Text = Val(MSComm1.Input)rnEnd SelectrnEnd SubrnrnPrivate Sub Timer1_Timer()rnSelect Case Text1.TextrnCase "01"rnText1.Text = "01"rnSendKeys "a"rnCase "02"rnText1.Text = "02"rnSendKeys "b"rnEnd SelectrnEnd Subrn串口助手能<em>接收</em>到<em>数据</em>01 02. 下位机发送01,02
boost异步通信,async_read_some始终接收不到数据
我写了最简单boost异步通信例子,async_read_some始终<em>接收</em><em>不到</em><em>数据</em>。<em>接收</em><em>数据</em>长度始终0,打印empty。甚至客户端断开连接后,仍打印empty,服务端对连接断开无反应。rnrnboost版本为1_69。客户端代码,发送<em>数据</em>功能。服务端代码,async_read_some<em>接收</em><em>数据</em>功能,如下:rnrn```rnclass clientsrnrnpublic:rn clients(std::string str_address,int nport,int id_val)rn :m_ep(boost::asio::ip::address::from_string(str_address.c_str()), nport), _id(id_val)rn rn start();rn rn void run()rn rn m_io.run();rn rn void start()rn rn boost::shared_ptrsock(new boost::asio::ip::tcp::socket(m_io));rn sock->async_connect(m_ep,boost::bind(&clients::conn_handler,this,boost::asio::placeholders::error,sock));rn rn void conn_handler(const boost::system::error_code& ec,boost::shared_ptr sock)rn rn if(ec)rn rn std::cout << "id: " << _id << " connect wrong" << std::endl;rn return;rn rn std::cout << "id: " << _id << " connect right to address:" << sock->remote_endpoint().address() << std::endl;rn sendtimer_=std::make_shared(m_io);rn sendtimer_->expires_from_now(boost::posix_time::milliseconds(500));rn sendtimer_->async_wait(boost::bind(&clients::do_write,this,sock));rn rn void do_write(boost::shared_ptr sock)rn rn char sz_send[512]=0;rn sprintf(sz_send,"%d_hello",_id);rn m_buf.clear();rn for(int i=0; iasync_write_some(boost::asio::buffer(m_buf),boost::bind(&clients::write_handler,this,boost::asio::placeholders::error,sock));rn rn void write_handler(const boost::system::error_code& ec,boost::shared_ptr sock)rn rn if(ec)rn rn std::cout << "id: " << _id <<< std::endl;rn rn elsern rn sendtimer_->expires_from_now(boost::posix_time::milliseconds(500));rn sendtimer_->async_wait(boost::bind(&clients::do_write,this,sock));rn rn rnprivate:rn boost::asio::io_service m_io;rn boost::asio::ip::tcp::endpoint m_ep;rn int _id;rn std::vector m_buf;rn std::shared_ptr sendtimer_;rn;rnrnint main(int argc, char** argv)rnrn int id_val = 0;rn if(argc>1)rn rn char* ch_val = argv[1];rn id_val = atoi(ch_val);rn rn int nport = TARGET_VALUE_PORT;rn std::string str_address = TARGET_VALUE_IP;rn std::cout << "id: " << id_val << " client start" << std::endl;rn clients cl(str_address, nport, id_val);rn cl.run();rn std::cout << "id: " << id_val << " client end" << std::endl;rn return 0;rn rnrn```rnrn```rnclass serversrnrnpublic:rn servers(boost::asio::io_service& io_ser, int nport):rn m_acceptor(io_ser, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), nport))rn rn accept();rn rnrn void accept()rn rn std::cout << "prepare accept" << std::endl;rnrn boost::shared_ptr sock( new boost::asio::ip::tcp::socket(m_acceptor.get_io_service()) );rn m_acceptor.async_accept(*sock, boost::bind(&servers::accept_handler, this, boost::asio::placeholders::error, sock));rn rnrn void accept_handler(const boost::system::error_code& ec, boost::shared_ptr sock)rn rn if(ec)rn rn return;rn rnrn std::cout<< sock->remote_endpoint().address() << std::endl;rn sock->async_read_some(boost::asio::buffer(m_buf), boost::bind(&servers::read_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, sock));rnrn accept();rn rnrn void read_handler(const boost::system::error_code& ec, std::size_t bytes_transferred, boost::shared_ptr sock)rn rn if(ec)rn rn std::cout << "error" << std::endl;rn return;rn rnrn if(bytes_transferred==0)rn rn std::cout << "empty" << std::endl;rn rn elsern rn std::string tmpstr(m_buf.begin(), m_buf.end());rn if(!tmpstr.empty())rn rn std::cout << "Recv Data" << tmpstr << std::endl;rn rn m_buf.clear();rn rnrn sock->async_read_some(boost::asio::buffer(m_buf), boost::bind(&servers::read_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, sock));rn rnprivate:rn boost::asio::ip::tcp::acceptor m_acceptor;rn std::vector m_buf;rn;rnrnint main(int argc, char** argv)rnrn boost::asio::io_service io_service;rn int nport = LISTEN_VALUE_PORT;rn servers srv(io_service, nport);rn io_service.run();rnrn return 0;rnrn```
CommandLineRunner 里得到的数据页面接收不到
方法没问题,但获取到的值传不过去rn rnrn rnrn```rn @Componentrnpublic class JobCLR implements CommandLineRunner rn protected final Logger logger = LoggerFactory.getLogger(JobCLR.class);rn @Autowiredrn private JobService js;rn @Overridern public void run(String... args) throws Exception rn System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载<em>数据</em>等操作<<<<<<<<<<<<,jobsList);rn rn for(Jobs l :jobsList) rn System.out.println(l);rn rn rn rn rnrn rn```rnrnrnrnrn rn rn 页面rn rnrnrn```rn rn rn rn rn 24-36万rn rn rn rn 绩效奖金 带薪年假rn rn rn```rnrn
kafka消费者kafka-console-consumer接收不到数据
发送端 <em>接收</em>端 问题 采用内置的zookeeper,发送端发送<em>数据</em>,<em>接收</em>端能够<em>接收</em><em>数据</em> 但是采用外置的zookeeper,发送端发送<em>数据</em>,<em>接收</em>端一直<em>接收</em><em>不到</em><em>数据</em> 解决: 先判断主题是否一致,如果一致就在关闭kafka ./kafka-server-stop.sh ../config/server.properties 修改一下配置,确保这些配置已加上,不要用localhost,在listene...
axios post 后端接收不到数据
1.是因为<em>数据</em>格式不对,通俗来说,后端需要的是JSON字符串(formData类型),不是对象(Request Payload格式),而axios默认的post方法是以对象形式发送,比如 { id:1, lastid: 3 } 变成JSON对象(Request Payload) 方法一:【用 URLSearchParams 传递参数】let param = new U...
RS485接收有问题,接收不到数据
我在调RS485。发送是OK的,<em>接收</em>却是一直<em>接收</em><em>不到</em><em>数据</em>,我已经使能<em>接收</em>了。rnrn用RS232RS485转接头,一头连PC,一头连板子。rn测试发送,在代码里让板子发<em>数据</em>,PC来接,这是OK的。rn但是测试<em>接收</em>,让PC来发,板子来接,就接<em>不到</em><em>数据</em>,我用示波器看了PC确实有发<em>数据</em>出去。rnrnrn是不是提供的电压不对,还是因为有干扰?rn搞不懂,大家帮帮忙,多指教哦,谢谢!
使用串口调试器接收不到数据的问题
PC和笔记本用232线相连,使用串口调试器2002,PC端口为COM1,笔记本端口为COM5,其他参数设置都一直,波特率9600,<em>数据</em>位8,校验位None,停止位1。rn打开串口后可以看见发送字节不停地增加,但是另一方的接受字节还是0rn请问是什么原因呢?
stm32串口接收不到正确数据
cc2530通过串口以数组方式发送4个<em>数据</em>,定义地是unsigned char类型rn下面是stm32提供的一个串口接<em>接收</em>函数rnuint16_t USART_ReceiveData(USART_TypeDef* USARTx)rnrn /* Check the parameters */rn assert_param(IS_USART_ALL_PERIPH(USARTx));rn rn /* Receive Data */rn return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);rnrn这个函数自己也尝试着改过,但是总是收<em>不到</em>正确的<em>数据</em>,求大神分析一下,该怎么样处理,这个函数返回的<em>数据</em>形式到底是怎么怎样的,前面的那个强制装换是不是把<em>数据</em>给边失真了,表示C语言小渣渣[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/54.gif][/img]求大神,包大腿
fetch post 后台接收不到数据问题
这两天在做fetch()的post,可是传递到后台,怎么都是null,GET PUT都没有问题,就是post有问题,试过网页的没有问题,但是post的就是不行,使用了网上的 method: &quot;POST&quot;,             mode: &quot;cors&quot;,             headers: {                 &quot;Content-Type&quot;: &quot;application/...
ajax接收不到struts2返回数据的问题
前台发送ajax请求后,确定后台已经成功<em>接收</em>到<em>数据</em>,并且正确运行并返回给前台,但却显示不出<em>数据</em>。 首先,要确定ajax请求的格式是正确的: $.ajax({ url: ..., method: "get", data: {...}, dataType: "json", success: function(data){ if(data.result == true){ ...
spcomm,怎么接收不到正确的数据
varrn Form1: TForm1;rn rbuf,sbuf:array[1..8] of byte;rnimplementationrnrn$R *.dfmrnrnprocedure TForm1.Button2Click(Sender: TObject);//给变量赋值rnbeginrn sbuf[1]:=byte($f0); //帧头rn sbuf[2]:=byte($01); //命令号rn sbuf[3]:=byte($ff);rn sbuf[4]:=byte($ff);rn sbuf[5]:=byte($01);rn sbuf[6]:=byte($f0); //帧尾rnend;rnrnprocedure TForm1.Button1Click(Sender: TObject);//发送代码rnvarrn HSendStr,DSendStr,sendstr : string;rn i : integer;rnbeginrn for i := 1 to 6 dorn beginrn comm1.WriteCommData(@sbuf[i],1);rn sleep(200);rn sendstr := '';rn sendstr:=sendstr + inttohex(sbuf[i],2)+'';rn sendstr:='发送'+sendstr;rn memo1.lines.add(sendstr);rn memo1.lines.add('');rn end;rnend;rnrnprocedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;//<em>接收</em>代码rn BufferLength: Word);rnvarrn viewstring,rstr : string;rn i : integer;rnbeginrnrn SetLength(Rstr, BufferLength);rn move(buffer^,pchar(Rstr)^,bufferlength);rn for i:=0 to bufferlength dorn memo1.Lines.Add(Rstr);rn Memo1.Invalidate;rn viewstring := '';rn move(buffer^,rbuf,bufferlength);rn for i := 1 to bufferlength dorn beginrn //viewstring:=viewstring+ inttohex(rbuf[i],2)+'';rn viewstring := viewstring + inttohex(rbuf[i],2)+'';rn memo1.lines.add('<em>接收</em>' + viewstring);rn memo1.lines.add('');rn end;rnrnend;rnrn<em>接收</em>的显示:rnrn<em>接收</em>F8rnrn<em>接收</em>F1rnrn<em>接收</em>FFrnrn<em>接收</em>FFrnrn<em>接收</em>F9rnrn<em>接收</em>F8rnrn1、为什么<em>接收</em>到的不是发送的?rn2、发送16进制数,<em>接收</em>的buffer里是10进制的?不然为什么显示时要用inttohex(rbuf[i],2)?
为什么 recv函数接收不到数据? 高分!
if(connect(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==INVALID_SOCKET)rn rn closesocket(fd);rn return "00000";rn rn ioctlsocket(fd,FIONBIO,(unsigned long*)&argp); //设置非阻塞模式rn int sendResult = send(fd,t,sendLen,0); //向server端发送一个消息rn int intsize;rn intsize=t.GetLength();rn if(sendResult==SOCKET_ERROR)rn rn closesocket(fd);rn return ;rn rnrn char recvBuf[64];rn memset(recvBuf,0,64);rnrn int recvResult = recv(fd,recvBuf,64,0); //为何<em>接收</em><em>不到</em><em>数据</em>?rnrn我做的是client,我向 server 端发送一个消息后,Server端回立刻给client回执一个消息,而client为什么recv<em>不到</em><em>数据</em>?
下面的程序为什么接收不到UDP数据
namespace XXXrnrn public class YYY : System.Web.UI.Pagern rn protected System.Net.Sockets.Socket RecvSocket;rn protected System.Web.UI.WebControls.TextBox RecvText;rn protected Thread t;rnrn private void Page_Load(object sender, System.EventArgs e)rn rn if (!Page.IsPostBack)rn rn RecvSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);rn IPEndPoint lep = new IPEndPoint(IPAddress.Parse("192.168.0.55"), 7003);rn RecvSocket.Bind(lep);rn GetSocketData tws = new GetSocketData(RecvSocket, RecvText);rn t = new Thread(new ThreadStart(tws.ThreadProc));rn t.Start();rn rn rn ...rn rnrn public class GetSocketData rn rn private Socket RecvSocket;rn private TextBox RecvText;rnrn public GetSocketData(Socket _RecvSocket, TextBox _RecvText) rn rn RecvSocket = _RecvSocket;rn RecvText = _RecvText;rn rnrn public void ThreadProc() rn rn byte[] buff = new byte[50];rn IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);rn EndPoint tempRemoteEP = (EndPoint) sender;rn while (true)rn rn RecvSocket.ReceiveFrom(buff, ref tempRemoteEP);rn RecvText.Text += Encoding.ASCII.GetString(buff);rn RecvText.Text += "\n";rn rn rn rnrnrn我想用B/S写一个类似C/S模式下的服务器,不知道这样的用法对不对?
Telerik OpenAccess ORM Q1 2010 Part2(2010年3月9日版本)下载
Telerik OpenAccess ORM Q1 2010 Part2(2010年3月9日版本) 相关下载链接:[url=//download.csdn.net/download/fosoyo/2116657?utm_source=bbsseo]//download.csdn.net/download/fosoyo/2116657?utm_source=bbsseo[/url]
DevComponents C# 开发控件下载
C# 非常好用的开发控件 版本为:9.1 特别版的 相关下载链接:[url=//download.csdn.net/download/zhaoxiongxing/3129305?utm_source=bbsseo]//download.csdn.net/download/zhaoxiongxing/3129305?utm_source=bbsseo[/url]
HTML5 3D云层效果下载
html5 技术实现的3d云层技术 通过jQuery插件的引用实现了非常酷炫流畅的浮云效果逼真生动! 相关下载链接:[url=//download.csdn.net/download/caojun20101982/4580134?utm_source=bbsseo]//download.csdn.net/download/caojun20101982/4580134?utm_source=bbsseo[/url]
我们是很有底线的