473,761 Members | 10,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Slow response when executing Ping

57 New Member
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 2259

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

Similar topics

5
2733
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 the appointment collection to populate the calendar control. The performance getting the XML data is fine, but loading the data into the collection is slow. My question/problem is should I be using the collection, a dataset, or something else to...
8
11074
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 my code it takes about 10-12 secs to complete, but doing same request in my browser takes less than 1 sec. Can anyone explain this delay from within my code ??
12
4030
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 the initial page load can take anything from 10 minutes to over an hour. Nothing seems to occur during this time. The first page load is simply incredibly slow. It seems to 'hang' until someone else tried to load the default.aspx, though there...
6
6712
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 AS400 for the back end database and I'm experiencing slow response times when executing sql statements. Some select statement response times are bad. Not all, but some. And there doesn't seem to be a consistent factor in any of the sql statements...
5
2211
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 30 seconds to retrieve 10,000 records. That's only about 36 KBytes/sec. This is a 100BT switched network (not sure if it is vlan'd or through a router). Echo time averages 3ms. The back end is pretty much idle. It shows 'idle in...
3
2712
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 start the app & type in something into the text box, it stalls & won't display the text you've typed in. After a short while, the text appears & the results are loaded into the data grid. After the first time, it works perfectly; loading data in as...
2
19584
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' *********************** Starting new log output
3
8997
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: tomcat 4.1 (10g oracle jar) oracle 9i apache 2.0.46
9
13043
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 Domain. We have both Cold Fusion and ASP.NET apps on this server and the Cold Fusion apps do not display such slowness on their first start up of the day. Is there a way to improve the load times of ASP.NET apps? I'm having to justify to my boss...
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.