I am writing a program to simulate Go Back N method. I want to open two ports(ex 9999, 8888) on one IP address (ex 127.0.0.1). But when I open 2 port on local IP address and use 2 thread to handle, one for sending(port 9999), one for receiving response(port 8888), it allways show error message. Please help me to solve this. Thank alots.
since there may be more than 2 consecutive spaces, you need to iterate. This is how
I do this:
string s="whatever with many spaces";
} while (s.Length<len);
For very long strings with many sequences of multiple spaces, it may be more economic
to use a StringBuilder, and fill it in one pass using a bool that remembers whether last
char added was a space or not.
Sorry, but taking the trouble of using StringBuilder only makes sense if you succeed
in avoiding unnecessary copy operations, hence StringBuilder.Replace is not my choice at all.
Either you use String.Replace in a loop, or a one-pass populating StringBuilder.
BTW your initial values for i1 and i2 are not needed if you test after the loop (do-while).
I happen to have one here, one I wrote in C many years ago and then ported to C# a few years back, thanks for giving me a reason to revisit it. (Now I'll revisit my Split that honors quotes and escapes as well.)
subject = the string to compress
trash = list of characters to compress (usually " \b" -- SPACE and TAB)
replacements = what to replace them with (usually " " -- SPACE)
quotes = if you don't want compress within quotes, specify "\"" or "'"
escapes = not often used, but if for instance trash contains "n" and subject contains "\n"
and you don't want it replaced, specify "\\" for escapes and the "\n" will be
(quotes and escapes may be empty or null)
advanced: two characters may be specified for replacements (and I've forgotten why I allow it)
given trash="z" and replacements="xy"
then subject="zzz" becomes "yyx" (rather than "x")
I'm working on a system which would be able to dinamically load all kinds of multiplayer games.
In order for the system to know how to handle any game, I set up some ground rules using an abstract class named GameEngine.
Among other stuff, it contains an abstract ProcessMessage() method.
At first I thought of loading DLLs from a special folder, and analyzing every class which inherits GameEngine.
But then came another thought into my mind...
What if someone, instead of implementing a game, inherits GameEngine and puts down malicious code into ProcessMessage()?
My first solution is not to read DLLs from a directory, but to read only a DLL that I will code... Whenever I want to add another game, I would update the DLL...
However, this prevents other programmers from adding games to my program...
You should sign your plugins ( DLLs ) using Signcode.exe and also use a Dotfuscator like tool to prevenet (as much as you can) your dlls from being disassembled to their original source code. Don't forget SecurityPermissionAttributes which also add another level of protection to your distributed plug-ins(DLLs). Checkout:
Web site: http://msdn2.microsoft.com/en-us/library/ab4eace3(vs.71).aspx
MSDN Library: Assembly Security Considerations
Hope this helps...
Last Visit: 31-Dec-99 19:00 Last Update: 7-Dec-23 6:09