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... -
// pingnew.h
-
-
#pragma once
-
using namespace System;
-
using namespace System::IO;
-
using namespace System::Text;
-
using namespace System::Net;
-
using namespace System::Net::Sockets;
-
using namespace System::Web;
-
-
#define ICMP_ECHOREPLY 0
-
#define ICMP_ECHOREQUEST 8
-
#define MAX_TTL 256
-
#define PACKET_SIZE 32
-
-
namespace pingnew
-
{
-
public __gc class ICMP_Packet
-
{
-
public:
-
Byte Type;
-
Byte Code;
-
unsigned short Checksum;
-
unsigned short ID;
-
unsigned short Seq_no;
-
static Byte Data[]=new Byte[PACKET_SIZE];
-
-
};
-
public __gc class ICMP_pro
-
{
-
public:
-
void SendPacket(String *s);
-
//static Byte CreatePack(ICMP_Packet *pac)[];
-
};
-
void ICMP_pro::SendPacket(String *s)
-
{
-
Socket *st=0;
-
IPHostEntry *iphe=0;
-
try
-
{
-
iphe = Dns::Resolve(s);
-
Console::WriteLine(S"Host Entry :{0}",iphe->HostName->ToString());
-
IPAddress* ipad = __try_cast<IPAddress*>(iphe->AddressList[0]);
-
Console::WriteLine(S"IP Address : {0}",ipad->ToString());
-
IPEndPoint* ipe = new IPEndPoint(ipad, 80);
-
Console::WriteLine(S"IP Address End Point: {0}",ipe->ToString());
-
st=new Socket(ipe->AddressFamily,SocketType::Raw,ProtocolType::Icmp);
-
//st->Bind(ipe);
-
ICMP_Packet *packet=new ICMP_Packet();
-
packet->Type=ICMP_ECHOREQUEST;
-
packet->Code=0;
-
packet->Checksum=0;
-
packet->ID=unsigned short(DateTime::Now.Millisecond);
-
packet->Seq_no=0;
-
packet->Data=new Byte[PACKET_SIZE];
-
Console::WriteLine(S"Length :{0}",packet->Data->Length.ToString());
-
for(int i=0;i<PACKET_SIZE;i++)
-
{
-
packet->Data[i]=(Byte)'S';
-
Console::WriteLine(S"Data :{0}",packet->Data[i].ToString());
-
}
-
-
//Byte BytetoSend[]=new Byte[];
-
/*ICMP_pro *pro=new ICMP_pro();
-
BytetoSend=pro->CreatePack(packet);*/
-
-
/*to convert to byte*/
-
Byte packetArray[]=new Byte[PACKET_SIZE+8];
-
bool isLittleEndian=BitConverter::IsLittleEndian;
-
-
UInt16 cksum=packet->Checksum;
-
for(int c=0;c<packetArray->Length;c+=2)
-
cksum+=Convert::ToInt32(BitConverter::ToUInt16(packetArray,c));
-
cksum=(cksum>>16)+(cksum & 0xffff);
-
cksum+=(cksum >>16);
-
cksum=~cksum;
-
UInt16 id=packet->ID;
-
UInt16 seq=packet->Seq_no;
-
int index=0;
-
packetArray[index++]=packet->Type;
-
packetArray[index++]=packet->Code;
-
Byte temp[]=BitConverter::GetBytes(cksum);
-
Array::Copy(temp,0,packetArray,index,temp->Length);
-
index +=2;
-
temp=BitConverter::GetBytes(id);
-
Array::Copy(temp,0,packetArray,index,temp->Length);
-
index +=2;
-
temp=BitConverter::GetBytes(seq);
-
Array::Copy(temp,0,packetArray,index,temp->Length);
-
index +=2;
-
Array::Copy(packet->Data,0,packetArray,index,PACKET_SIZE);
-
for(Byte i=0;i<packetArray->Length;i++)
-
{
-
Console::Write(S" {0}",packetArray[i].ToString());
-
}
-
Console::WriteLine(S"");
-
IPEndPoint* endPoint = new IPEndPoint(Dns::GetHostByName(Dns::GetHostName())->AddressList[0],80);
-
EndPoint* senderRemote = __try_cast<EndPoint*>(endPoint);
-
Console::WriteLine(S"SenderRemote :{0}",senderRemote->ToString());
-
-
for(int j=0;j<=MAX_TTL;j++)
-
{
-
Byte RecvByte[]=new Byte[256];
-
st->SetSocketOption(SocketOptionLevel::IP,SocketOptionName::IpTimeToLive,j);
-
st->SetSocketOption(SocketOptionLevel::Socket,SocketOptionName::SendTimeout,500000);
-
st->SetSocketOption(SocketOptionLevel::Socket,SocketOptionName::ReceiveTimeout,500000);
-
DateTime dt=DateTime::Now;
-
int iRet=st->SendTo(packetArray,packetArray->Length,SocketFlags::None,ipe);
-
-
Console::WriteLine(S"Address :{0}",ipe->MaxPort.ToString());
-
if(iRet==-1)
-
{
-
Console::WriteLine(S"Error Sending Data");
-
}
-
else
-
{
-
Console::WriteLine(S"Data Sending to {0}\n",ipe->ToString());
-
}
-
//Console::WriteLine(S"Address :{0}",*(&senderRemote));
-
iRet=st->ReceiveFrom(RecvByte,RecvByte->Length,SocketFlags::None,&senderRemote);
-
TimeSpan ts=DateTime::Now -dt;
-
if(iRet==-1)
-
{
-
Console::WriteLine(S"Error Getting Data");
-
}
-
Console::WriteLine(S"Received Data :TTL={0,-5} IP={1,-20} Time={2,3}ms",j.ToString(),senderRemote->ToString(),ts.Milliseconds.ToString());
-
if((iRet==PACKET_SIZE+ 8+ 20) && (BitConverter::ToInt16(RecvByte,24)==BitConverter::ToInt16(packetArray,4))&& (RecvByte[20]==ICMP_ECHOREPLY))
-
break;
-
Console::WriteLine(S"20th Byte of Received Data :{0}",RecvByte[20].ToString());
-
for(Byte rb=0;rb<35;rb++)
-
{
-
Console::Write(S" {0}",RecvByte[rb].ToString());
-
}
-
Console::WriteLine(S"");
-
if(RecvByte[20]!=ICMP_ECHOREPLY)
-
{
-
Console::WriteLine("UnExpected Reply,Quitting...");
-
break;
-
}
-
}//for
-
}//try
-
catch(SocketException *e)
-
{
-
Console::WriteLine(S"Socket Exception : {0}",e->ToString());
-
}
-
catch(Exception *e)
-
{
-
Console::WriteLine(S"Exception :{0}",e->ToString());
-
}
-
}//sendpacket
-
};//namespace
-
-
and my main program is -
#include "stdafx.h"
-
#using <mscorlib.dll>
-
#include<conio.h>
-
using namespace System;
-
using namespace System::IO;
-
using namespace pingnew;
-
-
Int32 main(void)
-
{
-
ICMP_pro *pro1=new ICMP_pro();
-
pro1->SendPacket("172.20.20.28");
-
int d=getch();
-
return 0;
-
}
-
0 2259 Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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 ??
|
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...
|
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...
|
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...
| |
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...
|
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
|
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
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
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
| |
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...
| |