|
if (RequestIDs.Count < 5 && !threadGetRequests.IsBusy)
{
threadGetRequests.RunWorkerAsync();
}
This happens inside a button click. If RequestIDs > 5 then we don't need to go looking for more, we can just load one. That's the other thread, actually, but they both work the same sort of way.
if (timerLoadCases == null || !timerLoadCases.Enabled)
{
timerLoadCases = new System.Windows.Forms.Timer();
timerLoadCases.Interval = 5000;
timerLoadCases.Tick += delegate
{
if (RequestIDs.Count > 0 && !threadLoadCase.IsBusy)
{
threadLoadCase.RunWorkerAsync(RequestIDs[0]);
RequestIDs.RemoveAt(0);
}
};
timerLoadCases.Start();
}
This is the other one, if we have a RequestID to download and there's none downloading now, we start downloading one. This adds them to a queue, we view from the queue.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello,
After a long hours of search in google, I wasn't able to find what I was looking for. I need pointers on how to write an application that will let me manage network bandwidth throttling. I want to run a local cable network and instead of relying on a 3rd party software, I want to write on for the sake of learning something new. It surely sounds challenging but I didn't thought it would be that challenging, at beginning.
Anyways, I want to limit bytes / sec on a certain IP with ports range etc. Maybe few guides in the right direction please?
Any help will be appreciated.
Thanks
|
|
|
|
|
Very big job. You basically have to write a proxy service that takes in requests on one side, makes the outward connection to the requested address on the other side and then passes the data between the two connections at the throttle rate you configured.
Not REALLY difficult, but very difficult to do well. Covers lots of different areas (threading, sockets, streams, etc...)
While I admire your want to learn this, you might want to settle down a bit and pick PARTS of this problem and learn each one very well first.
|
|
|
|
|
Thanks for replying, Ray. Actually, I want to do it like SoftPerfect's Bandwidth Manager or NetLimiter, i.e. without using a proxy.
I do have some fair knowledge of threading, streams and basic knowledge of sockets but I am willing to spend much time to improve on these areas. There's no haste and I have lots of time on hands to learn all the required stuff. The bottomline is, I just want to do it whether I convert it to a full-blown software or not.
Basically, I am looking for guides on how network bandwidth limiting can be done on windows using C# .NET or maybe just generally. For a start, I will probably be testing it on my home network by limiting speed on all ports on my desktop PC.
Thanks for help.
|
|
|
|
|
it is a difficult thing to do. I think what you are trying to write is what's called a "traffic shaper". you will probably need some kind of a low level proxy, through which all data packets will go through, so that you can control the rate in which these packets are passed over the network.
This proxy would have to use something like the winpcap library (or libpcap if you're not working on windows).
anyway, good places to start are: this article[^], which uses raw sockets to handle packets, and this one[^], which ports winpcap to c#
there are no facts, only interpretations
|
|
|
|
|
Hi , did u find the way? i really need it!
|
|
|
|
|
Well with how well HttpWebRequest worked reading a file, i though FTP would be just a s easy, not quite so, i have:
FtpWebRequest request =(FtpWebRequest)WebRequest.Create(@"ftp://address/1.txt");<br />
request.Credentials = new NetworkCredential("username", "password");<br />
request.Method = WebRequestMethods.Ftp.AppendFile;<br />
Stream FS = request.GetRequestStream();<br />
StreamReader SR = new StreamReader(FS, true);<br />
string line = SR.ReadLine();
I imagined that that would read the file, i was wrong, says that the stream is not readable.
So apart from the not being able to read the file, i need to be able to edit the file, and there would be the possibility of multiple people trying to edit it at the same time, how would i do this?
(No two people would be editing the same line in the file, if that makes any difference at all)
So err, any help or suggestions would be great
|
|
|
|
|
Perhaps if you try the Download protocol instead of the AppendFile protocol. The AppendFile protocol is used to append a file to another on the FTP server.
You can't edit a file over FTP. You have to first download the file, edit it, and then upload it.
If multiple people should be able to edit the file, you would have to download the latest version of the file to match it with the edited version before you can upload it. Also you should use some way to lock the file while you are matching it, so that two people can't do a match at the same time, perhaps rename the file while you are working with it.
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I am not 100% sure about that, but the methods seem similar to the HttpRequest.
The "request stream" is not readable, because you make your request to the server through it, it is a writable stream. There is another stream, the "response stream" which is sent to you after you call GetResponseStream() at some class (guess it was the request, too).
Get request stream, write data into if you need, get response stream, read it.
Regards,
d.mon
|
|
|
|
|
ok i need help here, I'VE LOST MY TUTORIAL IN MY BOOK, i want to send this "A2S_INFO" to a server through UDP/IP, How can i recieve his reply?
is this how to send?
System.Net.Sockets.UdpClient b = new System.Net.Sockets.UdpClient(serv, port);
b.Send(Encoding.UTF8.GetBytes("A2S_INFO"), Encoding.UTF8.GetBytes("A2S_INFO").GetLength(0));
|
|
|
|
|
hello developers... best regards!
I need to know how to get the data available in the dataGrid and insert (by a certain way) into sql server db?? i mean determining a datasource for the datagrid is simple, using a dataset, but if i wanna get this dataset and insert its data into a certain sql server table, how would it be?
Plz i need your help in that...
Ur help is much appreciated!
Sincerly urs, ali.;)
Knowledge Is KinG
|
|
|
|
|
hi
i want to print datagrid in vc# 2005 (not datagridview), and i found an article and class for datagridprinter in Codeproject but it's in VB and not work in c# .. does any one know how to do this ?
thanks ...
|
|
|
|
|
Hello
Maaybe you can check out this article[^]. DotNet 2.0 is a prerequisite on the target machine.
Regards
|
|
|
|
|
csc /t:module c:\form4.cs c:\form5.cs
when i use csc.exe through the command line this works and form4.netmodule is generated in
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
problem1:
the compiler always generates the .netmodule files in the above folder
how can i specify a path where i want to generate the .netmodule file
Problem2:
i am trying to do this through windows application(c#)
i am using this command on button_click
Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\\csc","/t:module c:\form4.cs c:\form5");
this command does not work properly
if there is some error in any file form4 or form5 it is indicated but when there is no error even then
the .netmodule file is not generated in the above mentioned folder
|
|
|
|
|
Hello,
you'll find CSC options in the MSDN documentation. /out specifies the output file, see: http://msdn2.microsoft.com/en-us/library/bw3t50f3.aspx
For compiling source code from within an application during runtime, I would suggest to make use of the System.CodeDom.Compiler classes (e.g. System.CodeDom.Compiler.CSharpCodeProvider) for compiling C#. There's also providers for other languages, unified under the ICodeCompiler interface (see MSDN).
Regards,
d.mon
|
|
|
|
|
I have a Client and a Sever, i connect the client to the server via Socket, now i'd like to send a file from the Client to the Server, i read about Socket.SendFile(fileName), but can't find how, from the server i have to receive the file using it (sendfile) in the client, i'd like to see an example, thank you!
|
|
|
|
|
Hy,
You don't need to send a file with the Send File method. The send method send a byte array. So use FileStream to read the byte content of the file and then send it to the client/server
FileStream fstream = File.Open(filename,FileMode.Open);
byte []buffer = new byte[fstream.Lenght];
fstream.Read(buffer,0,buffer.Length);
fstream.Close();
ClientSocket.Send(buffer);
It works fine on any kind of files. After you have received the file use FileStream to write the file (of course you should know the extension to put to the file).
Hope it helps
Do your best to be the best
|
|
|
|
|
I'm having problem in the Server Side;
How do i receive the file? and if i need the extension of the file, i have to send it with the client? and then how do i retrieve it? Thanks
else if (data.StartsWith("$UploadFile"))
{
}
|
|
|
|
|
You can create your own communication protocol. Let's say that the client sends a message to the server telling him that he will upload a file with a specified extension and size. The server sends back an acknowledge message and the the client sends the file.
Concerning the server. If you know the exact size of the file then you can do something like:
byte[] buffer = new byte[size];
client.Receive(buffer);
If you do not know the size of the file then you can write a sequence that reads data from the network in packets let's say 1024 long, like this:
ArrayList list = new ArrayList();
byte[] buffer = new byte[1024];
int read = 0;
int length = 0;
while ((read = client.Receive(buffer) != 0)
{
length += read;
list.Add(buffer);
buffer = new byte[1024];
if (read < 1024)
break;
}
At the end of this code you have inside the array list the entire file stored in 1024 length byte , arrays. After this just extract the byte arrays from the array list, like this.
buffer = new byte[length];
byte []temp = null;
int k = 0;
for (int i = 0 ; i < list.Count ; i++)
{
temp = (byte[])list[i];
for (int j = 0 ; j < temp.Length ; j++)
byte[k++] = temp[j];
}
Hope it helps.
Do your best to be the best
|
|
|
|
|
Ok, here is the Code, what's wrong?
//Client Side
FileStream fstream = File.Open(txtPathFile.Text, FileMode.Open);
byte[] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, buffer.Length);
fstream.Close();
Send("$UploadFile," + NameFileUpload.Remove(0, NomeFileUpload.ToString().LastIndexOf(@"\")).Remove(0, 1) + "," + buffer.Length + "|");
s.Send(buffer);
//Server Side
else if (data.StartsWith("$UploadFile"))
{
string[] b = data.Split(',');
string nameFile = b[1];
string size = b[2];
byte[] buffer = new byte[Int32.Parse(size)];
sock1.Receive(buffer);
File.WriteAllBytes(@"C:\" +nameFile, buffer);
}
|
|
|
|
|
Ok, here is the Code, what's wrong?
//Client Side
FileStream fstream = File.Open(txtPathFile.Text, FileMode.Open);
byte[] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, buffer.Length);
fstream.Close();
Send("$UploadFile," + NameFileUpload.Remove(0, NomeFileUpload.ToString().LastIndexOf(@"\")).Remove(0, 1) + "," + buffer.Length + "|");
s.Send(buffer);
//Server Side
else if (data.StartsWith("$UploadFile"))
{
string[] b = data.Split(',');
string nameFile = b[1];
string size = b[2];
byte[] buffer = new byte[Int32.Parse(size)];
sock1.Receive(buffer);
File.WriteAllBytes(@"C:\" +nameFile, buffer);
}
|
|
|
|
|
Please someone can help me?
|
|
|
|
|
my application shows an agent when it load
i would like when i right click on this agent it shows context menue
how can i do this
thank u
MD_NADA
|
|
|
|
|
I have just finished reading a book on C# and I would like to submit a review for it, but I can't find a link, is it the same as for submitting an article link?
|
|
|
|
|
Hello,
I am a noob to C# and would like to know the best method of parsing HTML. Here is an example of what I will be doing a lot of.
I would like to get the following variables
strVis = Detroit
intVisScore = 4
strHome = N.Y. Yankees
intHomeScore = 3
strInning = Final
strBoxScore = http://www.usatoday.com/sports/scores106/106278/MLB725547.htm
If you have something generic w/ good documentation I should be ok w/ that . I like learning the HOW.
Thanks!
Ryan
|
|
|
|
|