|
|
Hey, thanks a lot.
While I'm not using the exact code from the article you posted... (simply because I'd like to LEARN rather than simply USE) you've inspired me to learn how to use sockets - something I should have done a long time ago.
But again, thanks to all who posted.
-MartyExodus
|
|
|
|
|
MartyExodus wrote: simply because I'd like to LEARN rather than simply USE
Then you have a bright future!
led mike
|
|
|
|
|
MartyExodus wrote: PIEBALDconsult - The reason that i didn't do as the two of you said is simply this: System.Net.NetworkInformation doesn't exist in .NET 1.1,
I understand that. But I meant compile the method into its own v2.0 dll and reference it from your v1.1 executable. You said you have the Express version so you must have the v2.0 dlls and compiler. I haven't tried it, nor do I have a way to try it.
|
|
|
|
|
Well I once did my own ping in .NET 1.1
Her is the code; it will only compile and run within my environment,
but I'll show it anyway.
env.log() is just a logging function, and can be ignored (or used!)
class LP_Format does string formatting, is obvious
class LP_Thread basically is Thread, LP_BackgroundThread is derived from Thread
(sets IsBackground and calls Start).
remark: this is not thread-safe (since I use a static pingResult internally),
but that could easily be solved.
<pre>
public static bool Ping(string remoteIPadrString) {
pingResult=false;
LP_BackgroundThread thread=new LP_BackgroundThread("PING("+remoteIPadrString+")",
new LP_ObjectHandler(Pinger), remoteIPadrString);
if (!thread.Join(10000)) {
env.log(0, "Aborting PING("+remoteIPadrString+") due to timeout");
//thread.Abort();
LP_Thread.Sleep(1000);
}
return pingResult;
}
protected static bool pingResult;
protected static void Pinger(object arg) {
string remoteIPadrString=arg as string;
env.log(0, "---------");
env.log(0, "Ping("+remoteIPadrString+")");
IPAddress remoteIPadr=IPAddress.Parse(remoteIPadrString);
pingResult=false;
Socket socket=null;
try {
env.log(env.DETAIL2, "remoteIPadr="+remoteIPadr.ToString());
IPAddress[] IPAS=getIPAddresses();
env.log(env.DETAIL2, "got IP addresses");
socket=null;
foreach (IPAddress IPA in IPAS) {
try {
env.log(env.DETAIL2, "Ping("+remoteIPadrString+") using "+IPA.ToString());
socket=new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
socket.Blocking=false;
env.log(env.DETAIL1, "got socket");
EndPoint localEP=new IPEndPoint(IPA, IPEndPoint.MinPort);
EndPoint remoteEP=new IPEndPoint(remoteIPadr, IPEndPoint.MinPort);
socket.Bind(localEP);
ushort[] sdata=new ushort[20];
sdata[0]=0x0800; // ICMP echo request
sdata[1]=0; // ICMP checksum
sdata[2]=0x0100; // ICMP identifier
sdata[3]=0x0400; // ICMP sequence number
ushort val=0x6162;
for (int j=0; j<16; j++) {
sdata[j+4]=val;
val+=0x0202;
if (val==0x7963) val=0x6263;
if (val==0x7778) val=0x7761;
}
sdata[1]=ICMPchecksum(sdata);
env.log(env.DETAIL2,"checksum="+LP_Format.Hex4(sdata[1]));
byte[] bdata=new byte[40];
for (int j=0; j<20; j++) {
bdata[2*j]=(byte)((sdata[j]>>8)&0xFF);
bdata[2*j+1]=(byte)(sdata[j]&0xFF);
}
bool dump=false;
int len=socket.SendTo(bdata, remoteEP);
env.log(env.DETAIL1, "sent");
if (dump) {
env.log(env.DETAIL2,"sent len="+len);
for (int j=0; j<len; j+=4) {
env.log(env.DETAIL2, LP_Format.Hex2(bdata[j])+" "+
LP_Format.Hex2(bdata[j+1])+" "+
LP_Format.Hex2(bdata[j+2])+" "+LP_Format.Hex2(bdata[j+3]));
}
}
LP_Thread.Sleep(50);
int len2=0;
byte[] bdata2=new byte[300];
len2=socket.ReceiveFrom(bdata2, SocketFlags.Peek, ref remoteEP);
env.log(env.DETAIL1, "received");
if (dump) {
env.log(env.DETAIL2,"received len="+len2);
for (int j=0; j<len2; j+=4) {
env.log(env.DETAIL2, LP_Format.Hex2(bdata2[j])+" "+
LP_Format.Hex2(bdata2[j+1])+" "+
LP_Format.Hex2(bdata2[j+2])+" "+LP_Format.Hex2(bdata2[j+3]));
}
} else {
env.log(env.DETAIL2,"len="+len+" len2="+len2);
}
pingResult=true;
env.log(0, "Ping("+remoteIPadrString+") using "+IPA.ToString()+" is OK");
} catch(Exception) {}
try {if (socket!=null) socket.Shutdown(SocketShutdown.Both);} catch(Exception) {}
try {if (socket!=null) socket.Close();} catch(Exception) {}
socket=null;
}
} catch(Exception e) {
env.error(e);
}
try {if (socket!=null) socket.Shutdown(SocketShutdown.Both);} catch(Exception) {}
try {if (socket!=null) socket.Close();} catch(Exception) {}
env.log(env.DETAIL1,"ping("+remoteIPadrString+")="+pingResult);
}
</pre>
Cheers
Luc Pattyn
|
|
|
|
|
MartyExodus wrote: Is there any way I can import the functionality from .NET 2.0
Sure!
1- First install DotNet 2.0 on your machine.
2- Then add a reference to your project. Choose browse.
3- Browse to the DotNet 2.0 folder -I believe it's under "windows\system32"-. and choose the assembly you want to reference.
4- In your case the assembly should be "System.Net.NetworkInformation.dll ".
PS.
If you do this then DotNet 2.0 should also be installed on the user's machine.
Regards
|
|
|
|
|
Sing with me
You're not shy, you get around
You wanna fly, don't want your feet on the ground
You stay up, you won't come down
You wanna live, you wanna move to the sound
Got fire in your veins, burning hot, but you don't feel the pain
Your desire is insane, you can't stop until you do it again
But sometimes I wonder, as I look in your eyes
Maybe you're thinking of some other guy
But I know, yes I know how to treat you right
That's why you call me in the middle of the night, you say
It's urgent, so urgent, so urgent, just wait and see
How urgent my love can be, it's urgent
You play tricks on my mind, you're everywhere, but you're so hard to find
You're not warm, you're sentimental
You're so extreme, you can be so temperamental
But I'm not looking for a love that'll last
I know what I need and I need it fast
Yeah there's one thing in common that we both share
That's our need for each other anytime, anywhere
It gets urgent, so urgent, you know it's urgent
I wanna tell you it's the same for me
So urgent, just wait and see, how urgent my love can be, it's urgent
(Solo)
You say it's urgent, make it fast, make it urgent
Do it quick, do it urgent, gotta run, make it urgent
Wait it quick, want it urgent, urgent, emergency, urgent, urgent, emergency
Urgent, urgent, emergency, urgent, urgent, emergency
So urgent, emergency
|
|
|
|
|
Now what would be really cool is if Chris would set the backgound sound to this when someone submitted anything with URGENT in the title.
only two letters away from being an asset
|
|
|
|
|
So, how did you develop this song was it using ANNs or may a GA no I know it was a urgent desire to track down and thump in the head all of these urgent commands(sorry requests) - so you used A*.
Programmer: A biological machine designed to convert caffeine into code. * Developer: A person who develops working systems by writing and using software.
[ ^]
|
|
|
|
|
PLEASE DONT POST LOUNGE QUESTIOONS IN THE PROGRAMMING FORUMS
|
|
|
|
|
Oops. My bad. :->
|
|
|
|
|
I just hope most of them never figure out how to post their question multiple times.
led mike
|
|
|
|
|
HI All
The problem is this that i m retrievieng nodes and child nodes for a treeview from XMLDocument File when i am adding a new node the treeview doesnt update itself the node is added but when exit the application and again opening it then the node is displayed I want that when i add a node that is in xml the tree view upddate itself from the file agian.
SAS
|
|
|
|
|
Have you tried Refresh?
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: Have you tried Refresh?
The drink that tastes like Cola - only mintier.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I tried refresh but the problem is this that it doesnt work and when it refreshes itself a neww root is made like the previos one i want that when i refresh it it only detects the added root in the XML file
SAS
|
|
|
|
|
I've got the width of the text in my combo from the textrenderer class and i'm trying to set the combobox so that all the text is visible no matter how long the text is and without having acres of whitespace if the text is short.
Is there a way of setting the size of this area or measuring how much of the control is not part of this area so that i can resize the control accordingly?
Thanks
Russell
PS I promise this is my last daft Q of the day.
I've been looking at this some more and it no longer seems that daft to me. I've found 2 properties: ClientSize and DropdownWidth. These looked to be just the tools i need but then I realised that ClientSize doesn't take into account the size of the arrow and DropDown Width doesn't include the scrollbar. Maybe I need to know how to measure the arrow / scrollbar instead?
|
|
|
|
|
Rather than lose track of what's been posted in what order in the above message I thought i'd post a reply.
I've just checked the value of ClientSize and it's identical to the width of the control. Is this usual? Does it work differently depending on which control you call it on?
Russell
|
|
|
|
|
You could always use the Graphics objects MeasureString method using the font of the combobox. Iterate through the various strings in the combo for the longest one and then measure it.
Finally you can calculate and set the new width of the combobox:
cmbbox.Width = stringsize.Width + (cmbbox.Width - cmbbox.ClientSize);
Think that should be sufficient.
Hope that might be of some help.
Best regards!
-Larantz-
|
|
|
|
|
hello,
I've linked a file to start my app when you open it (like .doc files open Word)
The problem is that the System.IO.Directory.GetCurrentDirectory() gives the path of the file instead of the path where my exe resides.
Is there a way to change this back? (without hardcoding it)
thanks.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
Use Application.ExecutablePath
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
TNX !!
I used Application.StartupPath
|
|
|
|
|
You can get the path of your executable using this property:
System.Reflection.Assembly.GetExecutingAssembly().Location
Based on this, you can get the directory of the executable and make it the current working directory (by calling System.IO.Directory.SetCurrentDirectory with that path).
|
|
|
|
|
TNX ! I used Application.StartupPath
|
|
|
|
|
The System.Windows.Forms.Application.ExecutablePath property has the following comment:
Gets the path for the executable file that started the application, including the executable name.
You can then extract the path from here.
You could also use the executing assembly and work from there.
System.Reflection.Assembly.GetExecutingAssembly().Location
|
|
|
|