NIST Net can throttle bandwidth and simulate higher latencies. http://snad.ncsl.nist.gov/itg/nistnet/
Katalyst
Posts
-
Bandwidth Throttle? -
Interfacing with C from C#You can declare C functions in C# using the extern keyword along with the DllImport attribute. Once the function is declared, you just call into it. For example:
using System.Runtime.InteropServices;
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);MessageBox (0,"API Message Box","API Demo",0);
See the following and other articles on the topic: http://www.thecodeproject.com/csharp/c__and_api.asp There is no need for headers in C#. You just put all your code in the .cs class. You generally wrap your code within a namespace as a way of organizing things and to avoid name conflicts with other code -- it doesn't really correspond to a header.
-
Large File Transfer in Client-Server ApplicationsWhat kind of problems? If it's performance, you might experiment with different buffer options: * Increasing the size of the TcpClient buffers -- SendBufferSize and ReceiveBufferSize properties. * Wrapping the NetworkStream with a BufferedStream.
-
NetworkStream: To buffer, or not to buffer...I have a network stream that I am reading from, and I read from it one byte at a time (i.e., as opposed to using a stream reader or requesting a whole block). I set the receive buffer size directly on the associated TcpClient to be fairly large (i.e., ReceiveBufferSize = 250k). My question: Since I already have a buffer on the socket and I am reading one byte at a time, is there a benefit to wrapping my network stream with a buffered stream?
-
BufferedStream & StreamReaderI got around this problem by writing my own "ReadLine" for the buffered stream, eliminating the need for the StreamReader. Here it is, if you are interested. Please excuse the use of "goto", but it was the most natural (and efficient) way to write the code:
/// Gets the next line of text from the NTTP server. Reads from the /// buffered stream one byte at a time, until the characters \r \n /// have been encountered. Returns the text string, without the /// line terminators. private string ReadLine() { StringBuilder sb = new StringBuilder(); byte b; // Read bytes until the \r is encountered, adding it to the string. p0: b = (byte)bufStream_.ReadByte(); if (b != '\r') { sb.Append((char)b); goto p0; } // At this point, the \r has been seen, so we're looking for the // \n. If a second \r is encountered, loop back and look for \n // again. If any other character is found, add it to the string // and start over. p1: b = (byte)bufStream_.ReadByte(); if (b != '\n') { sb.Append((char)'\r'); if (b == '\r') { goto p1; } else { sb.Append((char)b); goto p0; } } return sb.ToString(); }
-
BufferedStream & StreamReaderI have some code that reads from a NetworkStream, retrieving both standard strings as well as binary data. The following code works:
connection_ = new TcpClient(host, port);
connection_.ReceiveTimeout = 30000;stream_ = connection_.GetStream();
bufStream_ = new BufferedStream(stream_);reader_ = new StreamReader(stream_, Encoding.GetEncoding("iso-8859-1"));
string str = reader_.ReadLine();
byte b = (byte)bufStream_.ReadByte();
But it's a little weird because the reader goes directly against the network stream for reading full lines as strings, but it goes through the buffered stream when reading individual bytes. Even though this works, I tried the following change:
reader_ = new StreamReader(bufStream_, Encoding.GetEncoding("iso-8859-1"));
But this doesn't work at all. When it gets to the ReadLine, it blocks indefinitely. Could this be a bug in BufferedStream? I'm using .Net 1.0, by the way.
-
Updating Visual Studio to .NET 1.1I've been using Visual Studio 7.0 to develop a C# application for a while. Today, I downloaded and installed the .NET 1.1 framework and SDK. But I can't figure out how to get Visual Studio to start using the new version of the SDK. If I rebuild my project and run, it's still using .NET 1.0... you can see this in the output: 'DefaultDomain': Loaded 'c:\winnt\microsoft.net\framework\v1.0.3705\mscorlib.dll', ... ... How do I get Visual Studio to start using the new version? Part of my problem may be that I didn't install Visual Studio in its default location. I put Visual Studio in one place, but I installed the new SDK in the default place (i.e., Program Files). I hope that I don't have to buy another copy of Visual Studio just to use the new SDK :(
-
JDK and Java 2 SDKHere's my understanding (others have touched upon the same): 1) JDK 1.1 (a.k.a., JDK or Java Developers Kit), is the version of Java that runs in browsers by default (i.e., without the need to download a plugin). It included the virtual machine, compiler, APIs, etc. This is several years old. 2) With JDK 1.2, they started also calling it Java 2, perhaps because of the minor version number. It includes the virtual machine, compiler, browser plugin, APIs, etc. 3) In JDK 1.2 - 1.3, they had a separate distribution called JRE (Java Runtime Environment). This was intended as a "thin" distribution for running Java applications only (i.e., no compiler, debugging, APIs, etc.). Intended for end-users. 4) In JDK 1.4, there doesn't seem to be a separate distribution of the JRE, although its included in the developer's JDK distribution. The APIs and capabilities have come a long way since JDK 1.1. From virtual machine changes like the Hotspot runtime vm, to numerous API changes for graphics, collections, etc.
-
keybd_event for .NET?I had a similar question that I posted a couple of days ago, with mixed results. See thread: http://www.codeproject.com/script/comments/forums.asp?msg=466571&forumid=1649#xx466571xx I tried calling keybd_event from C# through an extern declaration, like this:
[DllImport("User32.dll")] private unsafe static extern void keybd_event(byte bVk, byte bScan, uint dwflags, ulong* dwExtraInfo);
For me, this works the first time but is flaky after that. I'm not sure why, but it's possible that the last two parameter types are off -- I wasn't exactly sure what to use there. -
J# Not C#Just a guess, but maybe J# requires a fully qualified path name for FileReader (e.g., "C:\temp\foo.txt" rather than "foo.txt").
-
Accessing Num Lock state from C#I also tried unsafe code with a long pointer, but this doesn't work any better than just using longs:
[DllImport("User32.dll")]
private unsafe static extern void keybd_event(byte bVk,
byte bScan,
uint dwflags,
ulong* dwExtraInfo); -
Accessing Num Lock state from C#Thanks Nathan! That does the trick for getting the num lock state. I'm trying to figure out how to set the num lock now. I found a Win32 example that does this using keybd_event: keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0); The signature of this method is: VOID keybd_event( BYTE bVk, // virtual-key code BYTE bScan, // hardware scan code DWORD dwFlags, // function options ULONG_PTR dwExtraInfo // additional keystroke data ); I wasn't exactly sure what types to use for the last two parameters in the extern statement, so I tried "long" and crossed my fingers: [DllImport("User32.dll")] private static extern void keybd_event(byte bVk, byte bScan, long dwflags, long dwExtraInfo); This actually works the first time I call it, but it gets really flaky after that. I figure that I'm not using the right types for the last two parameters, so I'm stomping on memory somehow. Any clue what types I should use? Thanks again.
-
Accessing Num Lock state from C#I'd like to be able to determine if the keyboard has "Num Lock" enabled or disabled from C#, as well as to set this state programmatically from C#. I've found some info on how to do this in Win32 in C using "GetKeyboardState" and "keybd_event", but I'm not sure how to call this from C# or if there is a more direct approach in C#.