|
Good answer.
A quick question on this: I have been missing out on object.ReferenceEquals, so I have typically written my == operator along the lines of
public static operator==(MyType a, MyType b){
return ((object)a == null) ? (object)b == null : a.Equals(b);
}
public override bool Equals(object o){
MyType b = o as MyType;
if(b == null) return false;
else if((object)b == this) return true;
return (field1 == b.field1) &&
}
Is it better to use ReferenceEquals than the cast to object?
|
|
|
|
|
I don't know that it makes any difference to be honest... Does boxing* MyType to object have any overhead worth considering?
Using object.ReferenceEquals appears cleaner IMO as we are obviously comparing the references of each instance (or null ), rather than a cast to object when, apart from the null equality check, we never actually want it as an object.
*Edit: If MyType is a reference type then it's not boxing, but you get what I mean
Edit 2: See this SO thread[^]
modified 14-Dec-11 8:02am.
|
|
|
|
|
Nice link. And I think 'cast' is the word you want; if it's a value type then you don't need to bother with the null check anyway since a null can never be passed.
So basically it makes no difference as long as they've improved the compiler since .Net 2, which didn't inline ReferenceEquals calls. And yeah, any overhead is trivial and of academic interest only, but that's fun to think about sometimes.
|
|
|
|
|
hello guys... First of all, if this is wrong platform for this question, plz guide me to the right one. Second, I want to play with communication protocols like TCP/IP Model. I know basics for Network programming or Socket Programming but I dont know where to start for programming basic internet protocols. Any pointers to such topics will be appreciated. thnx
|
|
|
|
|
Not sure if this would be the wrong place but you at least kept your question wide open.
I think that you will need to be a bit more specific about what you want to accomplish. Are you just interrested in builing a chat app(tons of sources which i seriously don't need to point out). If you are aiming to controll a device of sorts you'll need to think about your own message protocol (which at least negotiates a version!). Either way let us know your aim and we'll give you a lot of hints, tips and/or links.
Cheers, AT
Cogito ergo sum
|
|
|
|
|
I guess im interested in Internet Security, if that is an appropriate term to use. I want to make sure that when I send some data over internet, its as much secure as possible. I guess I will need to play with .... Network Layer or something, I dont know. Let me know if I was able to help you.
|
|
|
|
|
Protecting data isn't so much a protocol issue as it is a cryptography issue
You should start learning basic cryptography primitives such as what a symmetric cipher vs asymmetric, in addition to key establishment protocols like diffie-hellman.
Keep in mind this is a very large field of study
Thanks,
Matthew.
|
|
|
|
|
There is more to security than just data encryption.
Although researching data encryption, understanding it and implementing it for non-trivial size messages will likely take some time so it is a start.
|
|
|
|
|
mmm, you could make your data secure by just making it un-understandable by having a really idiotic protocol or you can do what everybody else does... encrypt the data. There are lots of good examples which you can follow.
If it is just about file transfer you can take the easy(chicken??) way out and write yourself an app that creates a temp spanned-encrypted zip, transfer that, glue it back to gether and decrypt it.
I've done a lot on communication and protocols but hardly ever bother with security. This ball is for someone else I guess.
Cheers, AT
Cogito ergo sum
|
|
|
|
|
The most secure approach if you can't have offline key transfer is to first share a key using public key cryptography (realistically at the moment that means RSA), and then use that key for the data transfer. You can refresh the key periodically if you think key re-use is compromising your security (using the public key exchange protocol again, of course).
The easiest way to do that is use SSL. My sockets library also offers an RSA protected key exchange and you're welcome to have a look at that code to get some inspiration if you want to do it yourself.
|
|
|
|
|
overloaded Name wrote: I know basics for Network programming or Socket Programming but I dont know where to start for programming basic internet protocols.
What, you wanna learn the Network Time Protocol[^]?
Most protocols are described on the wikipedia. Is there any specific protocol that you are interested in?
Bastard Programmer from Hell
modified 12-Dec-11 12:02pm.
|
|
|
|
|
Eddy Vluggen claims to be: Bastard Programmer from Hell Holland
ftfy [see your wikilink]
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Whehe, aight - just corrected the link
|
|
|
|
|
hello and greeting to all...i got a question and looking for advise.
im building an app which run behind the window...not actually behind!
just an app which function is to looking for specific file, that will created everyday...
im using filewatcher and system tray to trace recently created file..
if there exits a file which i want and it just newly created, i will read that file and store into sql..after that..i delete it!
but when i delete, my app notify that it already delete..when i recheck again..the file still available but it cannot be opened..window prompt "the file is not exist..do u want to create new"
i google and found that i is bcos of the file is being shared between 2 activity which is, system watcher and stream reader...
can anyone help me how can i solve my problem...??
|
|
|
|
|
beh7606 wrote:
but when i delete, my app notify that it already delete..when i recheck again..the file still available but it cannot be opened..window prompt "the file is not exist..do u want to create new"
i google and found that i is bcos of the file is being shared between 2 activity which is, system watcher and stream reader...
can anyone help me how can i solve my problem...??
I haven't used the <a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx">FileSystemWatcher</a>[<a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx" target="_blank" title="New Window">^</a>] yet, but it might help to split the task into two separate tasks;
Once you processed a file, add it's path to a list.
Have a background-thread remove the files in that list.
Bastard Programmer from Hell
|
|
|
|
|
A couple of things to watch for:
1.
FileSystemWatcher looks for file system activity, and fires events when some file operations happen (or start to happen). The number of events is undefined; creating and filling a big file may generate several Changed events.
2.
FileSystemWatcher does NOT signal the end of a file operation, so you won't know when the writing process is done writing.
3.
One way to cope with the above is by inserting a delay: after a Created or a Changed event, just wait one minute, and only then do what you intended.
4.
Another work-around is using two files (this assumes you control the producer: have it create the actual file of interest, and when done, create a small "semaphore" file, optimally using simple code such as
File.WriteAllText("someFolder\semaphore.dat", "there is a new file called someFolder\myActualDataFile.txt");
Then have your FileSystemWatcher watch for the semaphore file only.
5.
When reading files or file streams, you must mjake sure to close them properly. Calling Close() or Dispose() normally takes care of that. Applying a using construct is a very good way to make sure it always happens:
using (StreamWriter swFromFile = new StreamWriter(logFileName)) {
swFromFile.Write(textToAdd);
...
swFromFile.Write(textToAdd);
}
|
|
|
|
|
hai! your solution is good!! thanks you...i will try to do it your way..hopefully it successful..thank you...!!! -sharing is caring- *_*
|
|
|
|
|
hi,
I want to use regular expressions for analyzing a url, but I can't get the regex groups as I would expect them to be.
My regular expression is:
@"member/filter(.*)(/.+)*"
The strings to match:
1) "member/filter-one"
2) "member/filter-two/option"
3) "member/filter-three/option/option"
I expect to get the following groups:
1) member/filter-one, /filter-one
2) member/filter-two/option, /filter-two, /option
3) member/filter-three/option/option, /filter-three, /option(with 2 captures)
I get the result for the first string, but fore the 2 others I get:
2) member/filter-two/option, /filter-two/option, empty string
3) member/filter-three/option/option, /filter-three/option/option, empty string
What can be the issue?
|
|
|
|
|
We do have a Regular expressions forum[^] - you should use that in future.
But, it's a Sunday, and I'm feeling generous!
If you name your groups instead of using anonymous groups it becomes clearer what the problem is:
member/filter(?<Prefix>.*)(?<Option>/[^/]+)*
Shows that all of the matches are in the Prefix group: nothing gets as far as the Option group because the "any character, repeated" clause in the prefix swallows the option text as well.
Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
modified 11-Dec-11 8:02am.
|
|
|
|
|
I second using the correct forum in the future.
benams wrote: (/.+)*
I've never gotten that sort of thing to work, so I expect it won't.
Try @"member/filter([^/]*)/([^/]*)/([^/]*)"
(And I like to name my groups too.)
|
|
|
|
|
I plan to make a Winforms app to sell, and am wondering how to avoid having it be pirated. I was thinking I could first get the user to create a UUID, inside of which there is his motherboard serial # and hardcode each distribution such that upon app start, there would be a check of that motherboard serial #, with the app actually running only if that matches. (I would set up a way for the customer to get a new distribution from me for other computers he may get.)
But there probably is a better way. Any ideas?
|
|
|
|
|
swampwiz wrote: But there probably is a better way. Any ideas?
Yes, don't bother.
You're wasting time on people who for the most part are not going to pay anyway, no matter what you do. You could use that time to actually make your program better. The idea you describe (and most others) only make it harder for legitimate users to use the program - suddenly they have to go through some sort process when they get a new computer? And the pirated version will just skip the UUID check (or whatever) entirely. Many paying users will then pirate the app even though they paid.
There are a couple of things that work to some degree:
- dongles (or other custom hardware). These things always break and cost a fortune for you just to set up the infrastructure. Only worth it for corporate applications that cost thousands per seat or if you intend to create a whole new platform.
- moving the functionality to a server. Works best if it's inherently an online program (multiplayer game etc), otherwise users will hate you.
- making the app free. Maybe with ads, or in-app purchases. Some may mess with that, but large scale piracy is unlikely because there isn't much to save.
Anything else can be broken, and will be, if the app is popular enough. And if it isn't popular, why waste time on such things?
|
|
|
|
|
Spot on!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
If you want to avoid piracy then only distribute your app on a single box that is disconnected from the internet. Otherwise there is no foolproof method. If they want it badly enough they will hack it
No comment
|
|
|
|
|
swampwiz wrote: how to avoid having it be pirated
Just make it so no one wants it (which is very likely anyway) and no one will steal it.
I'd rather have a lot of people using my free program.
modified 10-Dec-11 15:27pm.
|
|
|
|