473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Slow response when executing Ping

i did a program in vc++.net for ICMP communication using sockets.But when i execute it i received a very slow response...is there any configuration to be made on the server..or any other thing?.. i don't know the reason for slow response...i included the code for this...plz solve my problem...

Expand|Select|Wrap|Line Numbers
  1. // pingnew.h
  2.  
  3. #pragma once
  4. using namespace System;
  5. using namespace System::IO;
  6. using namespace System::Text; 
  7. using namespace System::Net;
  8. using namespace System::Net::Sockets;
  9. using namespace System::Web;
  10.  
  11. #define ICMP_ECHOREPLY 0
  12. #define ICMP_ECHOREQUEST 8
  13. #define MAX_TTL 256
  14. #define PACKET_SIZE 32
  15.  
  16. namespace pingnew
  17. {
  18.     public __gc class ICMP_Packet
  19.     {
  20.     public:
  21.         Byte Type;
  22.         Byte Code;
  23.         unsigned short Checksum;
  24.         unsigned short ID;
  25.         unsigned short Seq_no;
  26.         static Byte Data[]=new Byte[PACKET_SIZE];
  27.  
  28.     };
  29.     public __gc class ICMP_pro
  30.     {
  31.     public:
  32.      void SendPacket(String *s);
  33.      //static Byte CreatePack(ICMP_Packet *pac)[];
  34.     };
  35.     void ICMP_pro::SendPacket(String *s)
  36.     {
  37.         Socket *st=0;
  38.         IPHostEntry *iphe=0;
  39.         try
  40.         {
  41.         iphe = Dns::Resolve(s);
  42.         Console::WriteLine(S"Host Entry :{0}",iphe->HostName->ToString()); 
  43.         IPAddress* ipad = __try_cast<IPAddress*>(iphe->AddressList[0]);
  44.         Console::WriteLine(S"IP Address : {0}",ipad->ToString()); 
  45.         IPEndPoint* ipe = new IPEndPoint(ipad, 80);
  46.         Console::WriteLine(S"IP Address End Point: {0}",ipe->ToString()); 
  47.         st=new Socket(ipe->AddressFamily,SocketType::Raw,ProtocolType::Icmp);
  48.         //st->Bind(ipe);
  49.         ICMP_Packet *packet=new ICMP_Packet();
  50.         packet->Type=ICMP_ECHOREQUEST;
  51.         packet->Code=0;
  52.         packet->Checksum=0;
  53.         packet->ID=unsigned short(DateTime::Now.Millisecond);   
  54.         packet->Seq_no=0;
  55.         packet->Data=new Byte[PACKET_SIZE];
  56.         Console::WriteLine(S"Length :{0}",packet->Data->Length.ToString());    
  57.         for(int i=0;i<PACKET_SIZE;i++)
  58.         {
  59.             packet->Data[i]=(Byte)'S';
  60.             Console::WriteLine(S"Data :{0}",packet->Data[i].ToString());   
  61.         }
  62.  
  63.         //Byte BytetoSend[]=new Byte[];
  64.         /*ICMP_pro *pro=new ICMP_pro();
  65.         BytetoSend=pro->CreatePack(packet);*/
  66.  
  67.         /*to convert to byte*/
  68.         Byte packetArray[]=new Byte[PACKET_SIZE+8];
  69.         bool isLittleEndian=BitConverter::IsLittleEndian;
  70.  
  71.         UInt16 cksum=packet->Checksum;
  72.         for(int c=0;c<packetArray->Length;c+=2)
  73.             cksum+=Convert::ToInt32(BitConverter::ToUInt16(packetArray,c));  
  74.         cksum=(cksum>>16)+(cksum & 0xffff);
  75.         cksum+=(cksum >>16);
  76.         cksum=~cksum;
  77.         UInt16 id=packet->ID;
  78.         UInt16 seq=packet->Seq_no;
  79.         int index=0;
  80.         packetArray[index++]=packet->Type;
  81.         packetArray[index++]=packet->Code;
  82.         Byte temp[]=BitConverter::GetBytes(cksum);
  83.         Array::Copy(temp,0,packetArray,index,temp->Length);  
  84.         index +=2;
  85.         temp=BitConverter::GetBytes(id);
  86.         Array::Copy(temp,0,packetArray,index,temp->Length);
  87.         index +=2;
  88.         temp=BitConverter::GetBytes(seq);
  89.         Array::Copy(temp,0,packetArray,index,temp->Length);
  90.         index +=2;
  91.         Array::Copy(packet->Data,0,packetArray,index,PACKET_SIZE);  
  92.         for(Byte i=0;i<packetArray->Length;i++)
  93.         {
  94.             Console::Write(S" {0}",packetArray[i].ToString());
  95.         }
  96.         Console::WriteLine(S""); 
  97.         IPEndPoint* endPoint = new IPEndPoint(Dns::GetHostByName(Dns::GetHostName())->AddressList[0],80);
  98.         EndPoint* senderRemote = __try_cast<EndPoint*>(endPoint);
  99.         Console::WriteLine(S"SenderRemote :{0}",senderRemote->ToString()); 
  100.  
  101.         for(int j=0;j<=MAX_TTL;j++)
  102.           {
  103.             Byte RecvByte[]=new Byte[256];
  104.             st->SetSocketOption(SocketOptionLevel::IP,SocketOptionName::IpTimeToLive,j); 
  105.             st->SetSocketOption(SocketOptionLevel::Socket,SocketOptionName::SendTimeout,500000);
  106.             st->SetSocketOption(SocketOptionLevel::Socket,SocketOptionName::ReceiveTimeout,500000);
  107.             DateTime dt=DateTime::Now;
  108.             int iRet=st->SendTo(packetArray,packetArray->Length,SocketFlags::None,ipe);
  109.  
  110.             Console::WriteLine(S"Address :{0}",ipe->MaxPort.ToString());  
  111.             if(iRet==-1)
  112.             {
  113.                 Console::WriteLine(S"Error Sending Data"); 
  114.             }
  115.             else
  116.             {
  117.                 Console::WriteLine(S"Data Sending to {0}\n",ipe->ToString()); 
  118.             }
  119.             //Console::WriteLine(S"Address :{0}",*(&senderRemote)); 
  120.             iRet=st->ReceiveFrom(RecvByte,RecvByte->Length,SocketFlags::None,&senderRemote);
  121.             TimeSpan ts=DateTime::Now -dt;
  122.             if(iRet==-1)
  123.             {
  124.                     Console::WriteLine(S"Error Getting Data"); 
  125.             }
  126.             Console::WriteLine(S"Received Data :TTL={0,-5} IP={1,-20} Time={2,3}ms",j.ToString(),senderRemote->ToString(),ts.Milliseconds.ToString());   
  127.             if((iRet==PACKET_SIZE+ 8+ 20) && (BitConverter::ToInt16(RecvByte,24)==BitConverter::ToInt16(packetArray,4))&& (RecvByte[20]==ICMP_ECHOREPLY))
  128.                 break;
  129.             Console::WriteLine(S"20th Byte of Received Data :{0}",RecvByte[20].ToString());
  130.             for(Byte rb=0;rb<35;rb++)
  131.            {
  132.             Console::Write(S" {0}",RecvByte[rb].ToString());
  133.            } 
  134.            Console::WriteLine(S""); 
  135.             if(RecvByte[20]!=ICMP_ECHOREPLY)
  136.             {
  137.                 Console::WriteLine("UnExpected Reply,Quitting...");
  138.                 break;
  139.             }
  140.       }//for
  141.     }//try
  142.         catch(SocketException *e)
  143.         {
  144.             Console::WriteLine(S"Socket Exception : {0}",e->ToString());
  145.         }
  146.         catch(Exception *e)
  147.         {
  148.             Console::WriteLine(S"Exception :{0}",e->ToString());  
  149.         }
  150.   }//sendpacket
  151. };//namespace
  152.  
  153.  
and my main program is
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #using <mscorlib.dll>
  3. #include<conio.h>
  4. using namespace System;
  5. using namespace System::IO; 
  6. using namespace pingnew;
  7.  
  8. Int32 main(void)
  9. {
  10.     ICMP_pro *pro1=new ICMP_pro();
  11.     pro1->SendPacket("172.20.20.28"); 
  12.     int d=getch();
  13.     return 0;
  14. }
  15.  
Jun 16 '08 #1
0 2226

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use...
8
by: Soeren S. Joergensen | last post by:
Hi, From a win-service I do a HttpWebRequest to a secure url with some parameters to get some simple data from a remote system used later on in a worker thread. When making the request from...
12
by: Ian Murphy | last post by:
Hopefully someone else has seen something similar. We are experiencing an odd problem with aspnet, iis6 and w2k3. I have written a small site which works fine during the day. Each morning however...
6
by: MadMan2004 | last post by:
Hello all! I'm having a problem with a project I'm working on and I'd like to ask for anyone's input that might be helpful. I'm building a rather large front-end application connecting to an...
5
by: wespvp | last post by:
I'm seeing what seems like slow retrieval times over the network. I am retrieving a single field of about 100-120 characters per record. I am getting about 3 seconds per 1000 records - it takes...
3
by: Ant | last post by:
Hi, I'm using the text changed event of as text box to display a datagrid of search results dynamically. (The classic 'gets more specific the more you type in' scenario ). I find when I first...
2
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log'...
3
by: nonstopkaran | last post by:
hey i am handling a small application, it is running well. but very rarely it hangs... (i.e) loggin page itself will take more than 10m and the response will be very very slow. config: ...
9
by: SAL | last post by:
I have an ASP.NET 2.0 app that takes about 17 seconds to load on first startup but then is very fast after that. As I understand it from some posts in June, this is caused by the loading of the App...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.