|
It would appear that you have to close the CryptoStream to get all the data passed through to the NetworkStream (FlushFinalBlock doesn't seem to do it, which is odd, because when writing to a MemoryStream, it does work). However, GZipStream seems to have the same problem--you have to call Close to flush the final data.
The problem is, this closes the network stream! So I can't use the same socket to read any response.
Does anyone have any experience with this? It seems like I'll need to wrap the whole thing in a memory stream that allows the GZipStream and CryptoStream to close without affecting the NetworkStream. Is this correct?
Thanks!
Marc
Pensieve
Functional Entanglement vs. Code Entanglement
Static Classes Make For Rigid Architectures
|
|
|
|
|
I havn't had any experience with this (I'll try it out though when I get the chance which is god knows when ).
My guess is that the GZip compression method needs to have all the data in a buffer before it can finish compressing. The cryptostream may require the same thing although I'm not sure why.
As for GZipStream closing the network stream that is bizarre compared to the other streams because I've in the past opened a file-stream wrote some data using the FileStream, opened a StringWriter on the FileStream and wrote some data, closed it, opened a BinaryWriter and done the same thing. (I think, can't remember clearly).
If the MemoryStream method works then I'd use that if you're simply plugging out a pile of data, reading a response and then plugging out more.
Alternatively you could use some of the encryption classes in the System.Security namespace which work on byte arrays.
Just had a look in Reflector @ System.IO.Compression.GZipStream, it doesn't override the Close, neither does the DeflateStream which is what GZipStream is a wrapper around, so when you call Close it's actually calling close on the stream itself.
One possible solution looks like you may be able to call GZipStream.BaseStream.Close which shouldn't affect the network stream, only the DeflateStream.
Take a look in reflector and you'll (hopefully) see what I mean
Ed
|
|
|
|
|
Thanks for the feedback. BaseStream.Close also immediately caused the memory stream to be disposed.
This line in MSDN By default, GZipStream owns the underlying stream, so closing the stream parameter also closes the underlying stream. would make believe that the stream would remain open if I use the constructor that sets the "leave stream open" flag to true.
And indeed, it does leave the stream open. On further research, the problem appears to be in the CryptoStream--the NetStream reader isn't retrieving the data unless I explicitly close the CryptoStream on the writer.
But if I shove everything into a MemoryStream, then it works fine.
I swear, it's got to be me, but I can't see what I'm doing wrong!
Marc
Pensieve
Functional Entanglement vs. Code Entanglement
Static Classes Make For Rigid Architectures
|
|
|
|
|
Hmmm,
Which ICryptoTransform are you using?
I'm just wondering since the problem is with the CryptoStream, can you perform the encryption yourself using one of the System.Security.Cryptography classes.
Take a look at the source for System.Security.Cryptography.CryptoStream.Write. I know that it won't be as tidy as using the CryptoStream but could you do something similar to this in your code using the ICryptoTransform yourself.
I.e. you do the work not CryptoStream
Of course, this is assuming that the method with NetworkStream + GZipStream works fine.
Ed
|
|
|
|
|
|
Marc Clifton wrote: I hadn't even thought of that idea!
That makes 1.5 of us
I did think about it briefly but because I'd messed around a bit with DES and RSA encryption and found the classes relatively easy to work with I thought it'd be easier to write the encryption code yourself.
However I can't remember how I did the encryption and the two classes I thought I used look nothing like them (maybe they've changed for .NET 2.0?).
I'd be interested to find out which solution you decide to go for an for what reasons. May help me later on, I never know.
Ed
|
|
|
|
|
|
Not a problem
It's nice to help someone, I've asked a couple of questions here but never get a response, so I'm trying to make a change (albeit small )
I'll look forward to the article.
Ed
|
|
|
|
|
I am looking at orgainsing a custom constructor in one of my classes so that it calls through to my default constuctor. I understand this is done as follows:
Public TestClass()
{
//Default Constructor
}
Public TestClass(int testValue) :this()
{
}
The problem is i also want to call a base constructor, so i effectively want :
Public TestClass(int testValue) :base(int testValue2) : this()
Which is not valid syntax. Is there an easy way of capturing this in C#?
Cheers
AJ
|
|
|
|
|
AJ123 wrote: Is there an easy way of capturing this in C#?
You put the reference to the base on the default constructor. This chains the constructors together. For example:
class Program
{
static void Main(string[] args)
{
B b = new B(12);
}
}
class A
{
public A()
{
Console.WriteLine("I'm in the constructor of A");
}
}
class B : A
{
public B() : base()
{
Console.WriteLine("I'm in the constructor of B");
}
public B(int someValue) : this()
{
Console.WriteLine("I'm in the constructor of B({0})", someValue);
}
}
The output is
I'm in the constructor of A
I'm in the constructor of B
I'm in the constructor of B(12)
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Thanks Colin, seems obvious now. I was actually wanting the custom constructor of class B to call a different base class constructor than B's default constructor. Which is just been plain silly...
|
|
|
|
|
Hello, I want to do a Windows Form that doesn't have a close (X) and minimize (_) buttons as it normally have, it wan't it costum, or an image that I'll supply, OR that there will not be a control box AND no border, and inside the form I will supply an image with everything, but if I'll choose this, how will I be able to drag the window?
In anyways, the image inside is rounded and I don't know how to make the edges to be transperent, and not white\any-other-color.
(If someone know what is Steam, I'm talking about something like that.)
Thanks in advance... NaNg
|
|
|
|
|
|
|
NaNg15241 wrote: how will I be able to drag the window?
A very easy way to do it is to override WndProc on your form, handle WM_NCHITTEST , call the default, and if it returns HTCLIENT , change it for HTCAPTION . You'll be able to drag the form around by clicking on the client area.
I'm at home right now, but if you need help on that (or sample code), reply to this post and I'll show you some sample code that I have at the office. Those constants (WM_NCHITTEST , HTCLIENT , HTCAPTION ) can be looked up in Windows.h .
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
-- modified at 23:42 Sunday 12th March, 2006
|
|
|
|
|
This code will create a form that can be moved by dragging from the client area:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int WM_NCHITTEST = 0x84;
const int HTCLIENT = 1;
const int HTCAPTION = 2;
const int HTSIZE = 4;
const int HTBOTTOMLEFT = 16;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
{
if (m.Result == (IntPtr) HTCLIENT)
m.Result = (IntPtr) HTCAPTION;
}
}
}
I hope it helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
I am trying to keep a window open by handling the MouseMove event. However, the event is only ever raised when the cursor is over the splitter bar between the grid and description. Any help/suggestions?
|
|
|
|
|
I take it that you're capturing the Form.MouseMove event?
If so then what's happening is that the Grid and the Description are on top of the form and are blocking the mouse-movement for the form (basically).
The simplest way around this would be to set the Grid.MouseMove and Description.MouseMove events to be handled by the same handler as the form.
To do this, select the grid, click the events tab on the properties window in the form designer. You should be able to select the Form_MouseMove (or whatever it's called) routine in the MouseMove combo-box for the grid (they have the same delegate handler so they're compatible).
Repeat the process for the description.
Ed
|
|
|
|
|
Hi.
I have a DataGrid and ListView.
I want, when a row is added to datagrid by user, It displays in ListView too.
How can I do it?
Best wishes
|
|
|
|
|
Hi.
I have a collection( It write it) .
In a form I want to use a datagrid that when a user fill a row of it the contents, insert in collection.
In other words, with fill datagrid by user, my collection fill.
Please help me I this context.
Best wishes
|
|
|
|
|
Your datagrid usualy is bound to the dataTable that holds the data shown into you grid. Sou you must intercept the changes that ocur into the dataTable. This can be obtained with these events :
DataTable.RowChanging/DataTable.RowChanged
DataTable.RowDeleting/DataTable.RowDeleted
Intercept change to the table and update you collection.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Hello, I am looking for a way to get something similar to the tables that are seen in Word. I can draw a table onto a RichTextBox control using the appropriate RTF syntax, but what I would ultimately like is the ability to resize columns and rows using the mouse.
Does anybody know how this is done? Is there a third party control that allows this to happen?
I suppose you could trap mouse movement and such, but this seems really hard, because how would you even know where the table is within the textbox?
Thanks in advance,
Eric
|
|
|
|
|
Hello,
When coding a dialog box in C#, naturally there is going to be code that loads the dialog box with its initial values, responds to user input, and then retrieves the new values for use in the application.
Is it more appropriate to put this code into the Form class of the dialog box itself, or to have a separate class whose job it is to control the dialog box, and interface with it?
Thanks,
Rich
|
|
|
|
|
Troposphere wrote: Is it more appropriate to put this code into the Form class of the dialog box itself, or to have a separate class whose job it is to control the dialog box, and interface with it?
IMO, neither. Use data binding to connect an autonomous class that contains the properties for the data with the dialog. The data binding ensures that neither the dialog nor the underlying container class needs to know about each other, which makes your application more flexible and extensible. Here's[^] an article I wrote on the subject.
Marc
Pensieve
Functional Entanglement vs. Code Entanglement
Static Classes Make For Rigid Architectures
|
|
|
|
|
Thanks Marc! Your article is right on the money. And I really think your website is slick!
Rich
|
|
|
|