|
Hi, I would guess you are having a 32-bit/64-bit problem.
Are you using longs (i.e. 64-bit) for all lengths and offsets?
you are aware array indexing is using ints, are you?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yeah, from what i can see there shouldn't be a problem.
Send:
if((currentFile.Length-currentFile.Position) < PacketSize)<br />
count = (int)currentFile.Length-(int)currentFile.Position;<br />
else<br />
count = PacketSize;<br />
<br />
currentFile.Read(Data, 0, count);<br />
ServerConnection.Send(Data);<br />
ServerConnection.Receive(OK);
Recieve:
Rx = ClientConnection.Receive(Data);<br />
FS.Write(Data,0,Rx);<br />
ClientConnection.Send(OK);
Thats pretty much the bare bones of it. Using count makes sure i don't send a load of blank data at the end of the file, and it would only be set by calculating the difference between the length and position when this difference is less than the size of each chunk, so that would easily fit into an int.
Edit: *slaps self* Ouch, i got it, further up the code, i send a packet with some file information, Name, filesize etc. The other person then gets a message asking them if they want to accept the file. The filesize is currently stored as a 32-bit int. The person sending the file is gonna crash right there. Although no error message is given, or any indication something has gone wrong.
-- modified at 19:49 Tuesday 11th September, 2007
Damn, still fails to send the first peice of the file. Although im one stpe closer, previously it got stuck trying to parse the 64-bit file length from a string into a 32-bit int. Now it gets stuck err... just after? More investigation required.
-- modified at 19:57 Tuesday 11th September, 2007
Secrets Revealed. The first chunk is sent, i check the downloads folder, and sitting there is a few KB of the 4GB file, in all its glory.
|
|
|
|
|
The code snippets shown don't help at all, since all declarations are missing.
What is the type of currentFile, PacketSize, Data, etc?
what is the size of Data, the value of PacketSize?
Where is the try-catch, are you getting any exception?
Did you care to look at the value of count?
Communication (and interfacing in general) must be implemented in a very defensive way:
whatever can conceivably go wrong will sooner or later go wrong, so make provisions for
the worst case right from the start!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
currentFile is a FileStream, opened with File.Open(path, FileMode.Open);
PacketSize is an int currently at 512KB (524288 bytes)
Data is an array of bytes the same length as the PacketSize (except in the case of sending, when the remaining data is smaller than 512KB)
There is no try catch, and i cant test right now so i'll have to wait until tommorow to add stuff in and check.
count comes out fine, although there will be problems at the end of the file, because the file length will have been shortened to the maximun size of an int as will the current position, end result, count is 0. The last peice would fail. Still, thats not the problem now.
|
|
|
|
|
The progress bar. Set the value Maximum to the length of the file, and the Value of the bar to the current position. It was the quickest way for testing purposes, and now it comes back to haunt me.
I even checked how it would react with a console app, which revealed it would just be set to the maximum number for an int, if the file length was too long. But apparently, it makes the app stop, no cryptic error, nothing, it just stops.
Still, i'll just set the max to 100 and use a percentage. So glad i figured that out, i wouldn't have been able to sleep.
And tomorrow, lots of try and catch.
Thanks for the help.
|
|
|
|
|
You never told us about a progress bar.
It works with int, not long; and it throws exceptions when it is unhappy...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yeah, i didn't think it would be a problem, since i tested it with a console app, and it seemed fine. Alas.
Of course, if it crashed at setting the length of the progress bar, how did it send the first part of the file
It will forever be a mistery.
|
|
|
|
|
I'm porting a game I made for C++ into C# and I can't find an equivalent of getch(). I found the "Keys" object but it's not quite what I want (or maybe I'm not using it right). Basically what my game does is that it waits for the user to press a key (primarily the directional keys) and acts based on the key pressed.
[Edit]
I forgot to mention this isn't a console app it's a Windows App.
|
|
|
|
|
ReadKey from the .NET 2.0 framework should be what you are looking for. You can also test for Keys.Left , Keys.Right etc.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I couldn't find any Readkey when I typed in "Read". I tried using Keys.Left and so on but that class doesn't wait until you pressed a key which I need it to do. Alls it does is if a key is pressed return it otherwise return "None" and continue on.
But Thanks.
|
|
|
|
|
Console.ReadKey(true).KeyChar
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
So that'll work even though I'm not using a console window? (Just making sure)
|
|
|
|
|
You would have to use a console window in C# to do the equivalent of getch() in C++.
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
Yeah so my question is is there a way for the Windows App to wait until a key is pressed then return the key pressed?
|
|
|
|
|
Just respond to a KeyPress even - the application is already waiting for all kinds of input, and it would love to tell you if only you would listen. Basically, set the KeyPreview property of your main form to True, and then response to the KeyDown even from that form.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right))
}
I do not believe they are right who say that the defects of famous men should be ignored. I think it is better that we should know them. Then, though we are conscious of having faults as glaring as theirs, we can believe that that is no hindrance to our achieving also something of their virtues. - W. Somerset Maugham
My New Blog
|
|
|
|
|
I tried that (I put a MessageBox.Show("") in the if statement and it never popped up. I moved it out of the if and it still didn't show up. I set the KeyPreview to true.
|
|
|
|
|
I would like to get an object from one of the following known values:
1. Window Handle
2. Process Id
3. Associated Threads
Conversely, I could get one of the above values from an object and be able to perform my operation that way. Currently, I can create a new MS Word instance, and I can get all of the open MS Word applications into data objects, but I cannot tell which one is the one that I created. Does anyone know a way to do this? Thanks,
Jeff
|
|
|
|
|
Hi Jeff,
when you start a process with Process.Start() I expect Process.Id to contain the PID.
Does that help?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I am essentially attempting to ensure that my Microsoft.Office.Interop.Word.Application object corresponds to the new instance of MS Word that I just created. Yes, process has information such as process Id, process start time, window handle, etc., but the Word.Application object has none of those things in itself or any child elements (as far as I can tell). I was wondering if there is some way that I can test to see if the object that I am obtaining from the call to Marshal.GetActiveObject("Word.Application") is in fact the one that I created. There are certain tests that I am doing to ensure that I did get the proper one, such as ensuring that Word.Application.(Visible, Width, Height, X, Y) match the values that I set them to on the window with WinAPI calls, but there has to be a cleaner way to do this. Any additional info would be appreciated. Thanks,
Jeff
|
|
|
|
|
Sorry Jeff, I have no prior experience with Microsoft.Office.Interop.Word.Application
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
As one of my side projects I've been shuffling through the Adobe PDF 1.8 documentation, thinking about how to whip up a useful (if not entirely complete) library to print to PDF. PostScript takes a little bit to get used to but it's not bad.
My latest milestone was finding a way to retrieve a font from the system and it into the output stream (as PDF features embedded fonts). Now most of the major commercial vendors implement partial font embedding (i.e. only embedding the characters that you've used in your PDF document, rather than the entire font). I think this would be a useful addition to my homebrew library, but MSDN and Google are a bit light on documentation on the Font object.
So I suppose my question to you fine fellow programmers is, is there a way to take a .NET framework (2.0) Font object, remove all but a defined set of characters, and then write the remaining bits to a MemoryStream or FileStream? Would I have to do this unmanaged? Would I have to be so desperate as to break the font apart at the byte level in C++ and manually copy the relevant glyph data to the stream?
Please don't bother me... I'm hacking right now. Don't look at me like that - doesn't anybody remember what "hacking" really means?
|
|
|
|
|
Hello everybody
I have a txtbox where i write the name of my customrs in, the customer might be old and might be new
so the old one have an id and the name is in the database
what i want to do is when i begin write the name of the customer directly the nearst word appear in the txtbox
Ex:
in the database i have the name John
when i write the name to my customer Jony
when i press J whole the word John appear and ohn will be selected
when i press o also the word John still in the textbox but just hn is selected
when i press n the hn disappear and just still in the database Jon where i should continue the name myself because there no one similar in the database
Thank a lot
Assaf
|
|
|
|
|
All you need to is to use regular expressions or wild cards and pass the typed character to the reglar expression that searchs records in the database and your query returns the search criteria
LIKE %John% will search simliar names with John or Jane
|
|
|
|
|
Can I have an example or where i should search for, Please
Thanks for your help
Assaf
|
|
|
|
|
If this is a web app, search here and google for AutoCompleteExtender.
If it is a WinForm, which I don't know, but you should be able to catch the KeyUp / KeyDown / KeyPress event (which ever is suitable), retrieve the text entered by the user from the textbox, perform your search and populate the textbox with the relevant result.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|