|
Hi Guys,
I am creating a console application with certain systametic programming agenda, which will build a text file using the StreamWriter property. However, I want that before the text file is created on the execution of the console application, the user is shown a MessageBox asking for confirmation. Is is possible to display Message Box from within a Console Application?
Thanx for taking interest in my question,
Your help will be truly appreciated,
Rajdeep.NET
|
|
|
|
|
I think that the MessageBox is available when you add a reference to System.Windows.Forms , but then you're using a Windows UI-element on the console. You might want to consider replacing your MessageBox-functionality with ReadLine() and WriteLine statements
I are troll
|
|
|
|
|
Hi,
I don't know from which heaven I got this idea of storing last modified time in side the XML file, as a node. But I will tell you why I need this, and can you tell me how am I suppose to do it.
I want to prevent user to hack my file, they shouldn't be able to modify it and save it. If they do that, I delete that file and recreate a newer one.
(Like giving monkey a banana locked inside a transparent box, he can see it but can't eat it )
But to accomplish this I need to store the last modified time in the file and on save do not modify the last modified time.
If I am sounding crazy, let me know I will explain with an detailed example.
Thanks for you Precious time,
Karmendra
|
|
|
|
|
I got it, this,
File.SetLastWriteTime(FileName,LastWriteTime); would do the job.
Thanks.
|
|
|
|
|
That might only stop casual users, and it could cause the file to be deleted even if no changes were made.
I can write something that does the same thing and bypasses your "security".
You would likely have to store the date somwewhere inaccessable.
Or encrypt the date and a hash of the file or something.
I wouldn't bother trying to "secure" the file this way. Even Visual Studio doesn't. When I modify a file (even project files) with Notepad it merely asks if I want to reload the file and accept the "unauthorized" changes.
|
|
|
|
|
I am doing this not for cs files but my own configuration file, and it is not if user see the data but if he modifies it it will be replaced with default. i am storing a checkbox value true or false. Actually I am no good with encryption, I wasn't able to choose one to use.
I actually don't want the user to modify the config file outside of my application.
Can you tell me other ways to prevent it?
Thanks for your words.
Karmu
|
|
|
|
|
KSuthar wrote: Can you tell me other ways to prevent it?
No, I can't think of a way to be sure. And I don't think it's a reasonable goal.
If the user wants to modify the file outside the application, why not allow it?
It seems to me that the application needs to:
0) Check that the file exists
1) Load it into an XmlDocument
2) Check the schema
3) Read the value and confirm that's it either True or False
4) If anything in that process fails, then use the default, otherwise you got a valid value, why do you care how it got there?
You might also consider a binary file rather than an XML (text) file, to make modification more difficult.
|
|
|
|
|
Hello,
in the last few weeks i've read a lot about NAT Traversal and i searched after Tutorials and so on (i think i've read almost all what's there to read). On most webpages i've read about STUN, a protocol, which should help me to connect to another client behind a NAT-Router or a firewall. Now my question... if i understand STUN, STUN is ONLY there to give me the public IP-Address and the characterization of my NAT (Full Cone, OpenInternet and so on) here on CodeProject is a great tutorial for it. But so HOW can i connect with this informations to another client? Well OK, i have a server and there i save my informations about the peers (ID, STUN-Informations, favorite Port for UDP Connections) and if i have a OpenINternet-Client (directly plugged in to the internet, no router, no firewall) everything is really easy, because each listens on the specific favorite port.
But what's if my clients are behind a NAT, which gives a counting port number (for example, UDP connection to STUN-Server on Port 45001, to the Server 45002 and to the peers maybe 45003-60000). How can i find out on which port i can reach my peer? I know theres a technique called UDP Hole Punching, there both peers build up a connection to each other, but the Ports are my problem! Has somebody any idea, how to find out the ports of the peers? The peer2 must know on which port peer1 is connected and peer1 must know from which port peer2 wants to connect. Thats really tricky and i doesn't come further on this. I develope since a few days on it and yes, the server works, i can exchange all communication-information i want, but the connection between the peers itself, there i found no way to connect
Kind regards, i hope somebody has THE idea in this or has experience in this Traversal technologies.
|
|
|
|
|
I don't really have "THE" idea here, nor do I know much about STUN, but have you considered using UPnP to forward the ports?
|
|
|
|
|
Yes, i've thought about this solution,but i want that a lot of people could use the software i make, except which internet connection, so UPnP wouldn't work everywhere, a lot of routers has disabled UPnP and i don't want, that a "standard-user" must change the router configuration, the most people are afraid to doing this. So something like UDP Hole Punching would be the best way.But if you have a concrete example to doing this in UPnP i would like to test it 
|
|
|
|
|
Perhaps the code from my article[^] will work for you - there are people for which it doesn't work, but I think that the people for which it does work just don't usually take the effort of reporting that it works.. It works for me that's for sure
Hole punching would be better of course but UPnP is better than nothing (right?) I'm sorry I don't know enough about hole punching, last time I looked it up it didn't seem too hard but there's probably a 'catch' somewhere..
|
|
|
|
|
yes, that's maybe right, i'll test your code in this week. Well... back to UDP hole punching, i doesn't understand, how to find each others ports? because the most people have a "Port restricted Cone NAT", which means, that to a specific port from the router, only answers from a specific server from a specific port are accepted. But i can't see into the future, which port the router will use. 
|
|
|
|
|
softwarejaeger wrote: But i can't see into the future, which port the router will use
I don't think that's quite right, official sites say "an external host can send a packet, with source IP address X and source port P, to the internal host only if the internal host had previously sent a packet to IP address X and port P. " I think it means that as long as you send the first packet, you can receive packets as well, but only from the IP that you sent to and only from the port that you sent to. Both ends can send what looks like the first packet to them, so this isn't a problem, just send a bogus packet first (but it must be to the same IP/port combination as what you want to receive from)
|
|
|
|
|
Exactly, but how do i know from which port a data package from the other side will come? For example:
Step 1: Client 1 sends a UDP Package to the Server (IP: 1.1.1.1:1000)
Step 2: Client 2 sends a UDP Package to the Server (IP: 2.2.2.2:2000)
Step 3: Client 1 and Client 2 gets the UDP Informations from each other from the server
Step 4: Client 1 (LAN: 192.168.1.1:61000, WAN:1.1.1.1:1001)sends a UDP Package to Client 2 (2.2.2.2:2000) (!! Couldn't work! Port 2000 is reserved for the server-address and port)
Step 5: Client 2 (LAN: 192.168.1.2:62000, WAN:2.2.2.2:2001) sends a UDP Package to Client 1 (1.1.1.1:1000) (!! Same problem like in Step 4)
So... here you see the problem. I must find out from which port the Client 1 WILL send his data the same for Client 2. And there i found no solution.
|
|
|
|
|
Well that's really an unrelated problem - and there is no good solution. This is why most virtual networks (in the broadest sense) have at least 1 central server, even the P2P DHT networks do because otherwise you don't have a "starting point" from which to explore the other nodes. Now you could just keep it simple and have a rule that "I will talk on port 2000" and that would work, but without such a rule you need a known place to store which port goes with which address. I know it's ugly, it's just the way it is..
|
|
|
|
|
well a starting point is avaliable, that's the server, which holds the communication informations (id of the node, port from the listener, public ip, local ip and so on)...
|
|
|
|
|
Ok so, what is the problem then? You want to talk to a node on a different port then it says it opened?
|
|
|
|
|
Look at my previous post with the different steps. The NAT Browser doesn't use the same port for the connection to client 2 like to the connection of the server. And how can i "hit the right port?" i doesn't understand that 
|
|
|
|
|
Just open both ports then
|
|
|
|
|
can you specify that? or write a few lines of code, that i can follow you?
|
|
|
|
|
PunchHole(ip, 2000);
PunchHole(ip, 2001);
|
|
|
|
|
Well... if i had now the Method/Function "PunchHole" i could imagine what you mean. That's not a C# Problem from my side, it's a logical problem, what to do to get this connection. I can't open the port and make a connection, because the other side doesn't know on which port i send this package and the other side doesn't know on which port the other side will answer and to find that out is my problem 
|
|
|
|
|
Sure you know, 2000 and 2001, because that's what you specified, it's not random
|
|
|
|
|
How do i specifiy that? Well... you mean, that's on which port i listen right? But that would only works in a LAN, not in a WAN, my Router doesn't open a port if my PC listens on 2000/2001 for example. So i can't access Client1 from Client2 if i send a package to "Client1:2000" from Internet, because the router doesn't know what to do with Port 2000. That's right or not? 
|
|
|
|
|
Yes that's why you punch a hole before listening, but it's still the same port
|
|
|
|
|