|
Hi! I have made a Client and a Server applications. I want to send a file from the Server to the Client. This is how I do it:
<br />
ns is a NetworkStream which is connected.<br />
writer is a StreamWriter.<br />
<br />
The Srever:<br />
<br />
FileStream fs = File.OpenRead(path);<br />
long byteCount = fs.Length;<br />
writer.WriteLine(byteCount);
writer.Flush();<br />
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.CanWrite)<br />
{<br />
int length = fs.Read(buffer, 0, buffer.Length);<br />
ns.Write(buffer, 0, length);<br />
ns.Flush();
readBytes = readBytes + length;<br />
}<br />
<br />
The Client:<br />
<br />
FileStream fs = File.Create(Application.StartupPath + "\\buffer.nkl");
long byteCount = long.Parse(reader.ReadLine());
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.DataAvailable)<br />
{<br />
int length = ns.Read(buffer, 0, buffer.Length);<br />
fs.Write(buffer, 0, length);<br />
readBytes = readBytes + length;<br />
}
The problem is that the received file is trimmed - it isn't whole (sent file is 198 kb, received file is 23 kb). If I remove ns.DataAvailable it takes a long time and the file is almost complete (sent file is 198 kb, received file is 196 kb).
What am I doing wrong???
Still learning...
|
|
|
|
|
Hi,
you shouldn't give up once ns.DataAvailable is false, that could happen any time: maybe the server is temporarily busy (say waiting on disk I/O, serving other clients, ..) or the client has a more powerful machine, hence it would run ahead.
A better approach would be for the client to either just ignore ns.DataAvailable (now the client would hang if the server exits unexpectedly) or allow for a later retry (say when false, wait 100 msec and try again) which increases the odds, but exits gracefully when the communication really goes wrong.
If it goes wrong, add some logging statements to both server and client so you can see where it fails.
Example: Console.WriteLine("server: readBytes="+readBytes);
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
When the download is complete I can enter other commands to the server. If I have ns.DataAvailable, when I enter the command to my server to disconnect (the server should return "Disconnected") I receive a part of the transferred file (several words from it). As if there is still data in the stream.
But when the ns.DataAvailable is absent from the while loop, when I enter the command for download, the download begins but never ends. I have to close the client and then the buffer file is at 196 kb.
I am testing the application on my computer - both the client and the server (for an IP I am using localhost) so there shouldn't be a difference.
Still learning...
|
|
|
|
|
nike_arh wrote: I am testing the application on my computer - both the client and the server (for an IP I am using localhost) so there shouldn't be a difference.
Their relative priority (and hence the percentage of CPU cycles allotted to each of them) will depend on which process is in front!
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
In FirstWindow class:
* Has progress bar object named "progressBar1".
* Its value is updated in this class as the process runs.
In SecondWindow class:
* Has progress bar object named "pbSecond".
* This SecondWindow class invokes FirstWindow class but does not use (display) the
FirstWindow GUI.
* This SecondWindow sends the data to FirstWindow the data to be processed and save to the file.
Now, I had this kinda of crazy idea to try and was amazed it does work! I'm not certain on how this works... passing the pointer of the object?
FirstWindow class has this property:
public ProgressBar pBar
{
set { progressBar1 = value; }
}
public int DumpRFData(byte[] dat)
{
pBar.Maximum = dat.length;
for (int i = 0; i < dat.length; i++)
{
progressBar1.value = i;
... code sippet (for retriving dump data)
}
}
now in SecondWindow class:
public int DumpData()
{
byte[] data = new byte[1000];
FirstWindow fw = new FirstWindow();
fw.pBar = pbSecond;
fw.DumpRFData(data);
}
when the DumpRFData is invoked, the progress bar in SecondWindow is updated as the process in FirstWindow runs.
How could that be happening? Processed from the pointer or what?
|
|
|
|
|
It's not a pointer, it's a reference. This is pretty ugly, your dumpRFData method should be outside any UI class.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
right... I am in the middle of refactoring my source code to clean up the repeated functions and capsulate the classes with its appropriate methods.
|
|
|
|
|
Hi,
I need some urgent help on something.
I need to convert Expression<Func<T1, bool>> to Expression<Func<T2, bool>>.
I have a funtion that does T2 = Convert(T1)
In other words I need a function that does something like:
Expression<Func<T2, bool>> Convert(Expression<Func<T1, bool>> pSource) {
Expression<Func<T2, bool>> vResult;
...
...
...
T2 vOutpuParameter = Convert(vInputParameter);
...
...
...
return vResult;
}
Does anyone have any clues?
|
|
|
|
|
Hello
I'm trying to find some idea / method to draw railway pattern using Graphics gdi+
Google map gives a example to do some, I do not need to do exactly the same but something that can looks like a railway
The source information is an array of PointF
I'd a look on Pen.CompoundArray but I do not understand how it works from an atrray of PointF
Thanks for any help / suggestion
|
|
|
|
|
You mean a railway track ? I guess you draw two lines next to each other, then you draw small lines across it. I would think the best way to do that, would be to create a brush that defines a piece of track, then use that to draw your line.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
guess you draw two lines next to each other, then you draw small lines across it.
This is the obvious "brute force" way : needs a lot of calculation awikll fatten the code I really do not want to use that way
I would think the best way to do that, would be to create a brush that defines a piece of track, then use that to draw your line.
I also think that it will be a good way but I do not know how to define the brush ?
Do I have to create an external image ?
|
|
|
|
|
baranils wrote: I also think that it will be a good way but I do not know how to define the brush ?
You create a brush from a Bitmap, so you can load that from a file, or just draw it. In fact, I think the class you want is called BitmapBrush
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
You'll probably have to draw over the line twice. Read up on the compoundarray to get it to draw a double line (your railway lines). Then draw over that with a thick line and custom dash style to get sleepers.
|
|
|
|
|
Thank you
I will investigate that way !
|
|
|
|
|
Moving an array element to a variable.
When I started I didn't think just taking an element and copying to a variable was such a hassle.
OK, I have a string array defined as:
public static string[] Trux_Info = new string[20];
and I have a varaible define as
public static string port_in = "";
Now I thought that something like
port_in = Trux_Info[3]
would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right.
I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there.
I really need this element to go to this single variable, because after this happens then the processing can begin.
Any and all suggestion are appreciated.
Thanks
|
|
|
|
|
I tried it:
public static string[] Trux_Info = new string[20];
public static string port_in = "";
private void button1_Click(object sender, EventArgs e)
{
Trux_Info[0] = "Hello";
Trux_Info[1] = "There";
Trux_Info[2] = "This";
Trux_Info[3] = "Is";
Trux_Info[4] = "A";
Trux_Info[5] = "Test";
port_in = Trux_Info[3];
MessageBox.Show(port_in);
}
It show "Is" - which is what I would expect.
So, there is something you aren't telling us. Give us a cut-down-but-still-not-working sample of the code that isn't doing it's job, and tell us what it is doing instead.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Griff is right. There's something you're not telling us. What IS it doing and what are you EXPECTING it to do?? We also need to see a more complete code snippet showing the offending code.
|
|
|
|
|
Ok
It's one of those things where another of section of code was causing the problem. It had nothing to do with the array. Problem fixed array transfered properly.
Say it with me now, ROOKIE!!!!!!!!!!!!!!
I do appreciate the expediant answers. Consider this line/thread closed
Thanks
L.
|
|
|
|
|
Hi Everyone,
I have a project which was written long time back. Now we are in position to convert into C# source code but we found that we donot have any source code.
I need two favors from you.
1. How to convert the ocx file into C# source code without having the source code
2. How to convert VC++ source code into C# soruce code.
Thanks in advance
|
|
|
|
|
dwark106 wrote:
1. How to convert the ocx file into C# source code without having the source code
Why? If your COM component works well, just use it in a C# application (via COM interop ).
If you're stuck with the 'conversion' requirement, I suppose the easier solution is implementing from scratch the COM object functionality (i.e. 'the black box' way) in C# (in other words, I believe reverse engineering is not a good solution of your problem).
dwark106 wrote: 2. How to convert VC++ source code into C# soruce code.
For a C++ and C# expert the task should be fairly straightforward (if you were an expert of both languages then you probably wouldn't do or ask about...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi Pallini,
Thanks for your response.
1. Actually I donot know what are the functions are being used by this application(ocx). I am also thinking to write from the scratch, but I do not have source code, so that I can chop the function that is not needed.
2. I was looking the easier way to convert the application. Anyways I will take your suggestions.
|
|
|
|
|
1) Learn assembler. Disassemble OCX. Spend lots of time working out what the heck is going on. Code it in c#
2) Learn C++. Learn C#. Translate.
To be honest, if you are lacking the source code for the OCX, then the best thing you can do is re-write it from the original specification. Or (more likely) write the spec from the OCX behaviour, and then rewrite the OCX.
Good luck - you may need it...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
There are no conversion tools and nothing that is going to generate any kind of C# code for you. You have no choice but to study the existing OCX control and redesign and recode the control by hand in C#, or any other language for that matter.
|
|
|
|
|
I don't know how to put timer in form that clock would be moving..
public void Start()
{
timer1.Enabled = true;
this.Refresh();
}
public void Stop()
{
timer1.Enabled = false;
}
private void timer1_Tick_1(object sender, EventArgs e)
{
this.dateTime = DateTime.Now;
this.Refresh();
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dateTime = DateTime.Now;
this.analog_size(sender, e);
}
With this code i get current time and clock pointers are also showing the correct time..but they are not moving..what should i do to make them move??
Thanks
|
|
|
|
|
As far as I can see you wait for the timer to tick, but the timer isn't ticking. In Start() and Stop() methods you should use timer1.Start() and timer1.Stop() rather than timer1.Enabled .
Still learning...
|
|
|
|