Control properties of a .NET class

sampoo

Active member
Joined
Jun 12, 2004
Messages
25
Location
Belgium
Programming Experience
3-5
Hi,

I have been searching a lot, but didn't find, a solution for a quite sticky problem. Since in VB.NET almost everything (e.g. Sockets) have become classes instead of *visual* objects with events, i cannot control data anymore in a socket. I'm posting this question here, because it might be useful for other classes too.
So, eventually the question: ;)
In VB6, the socket, WinSock, was an object you could place on your form. When this socket was connected with a server, it could receive data, and when this happened, an event would be raised: DataReceived, with some arguments (size etc.). Since Socket in .NET has become a class, the events are gone, and i see no possibility of controlling a property, namely 'Available', which changes when data is received, and it contains the number of bytes available.

Is there any way to control a property (from which you do not have the source-code)? Should i use a different way to solve my problem? (My app doesn't follow a strict pattern in receiving and sending data)

If possible, I'd like not to use timers, they are very CPU intensive...



Thanks a lot for your help
 
I don't have any experience with sockets so unfortunately I won't be able to give specific help with that, but perhaps I could help you understand VB.NET a bit clearer.

It's true that most things are classes in VB.NET, but many of those classes are *visual* objects with events. Take a textBox for example. A textBox is a special type of class (called a control) that can be visually designed. The textbox control has certain properties that can modify it's visual appearance (BackColor, BorderStyle, ...) and these properties can be modified through the designer and the Property Explorer. The properties can also be modified through code during run time. It also has many events (TextChanged, Enter, Leave, ...) that can be "handled" by creating event handlers in the code page. All forms are also classes (in VB.NET) that can be designed visually (forms are also considered controls).

There are also other types of classes called components which offer a way to visually design properties for that class during design time. The System.Windows.Forms.Timer component is an example. The timer control is not visible during run time, but during design time you see an icon at the lower part (by default) of the designer. This allows you to make changes to certain properties visually (in the Property Explorer). You could also create a timer completely in code without using the designer: "Dim tmr as New System.Windows.Forms.Timer". When you do use the designer to create a timer, the designer creates this code for you (take a look in the Region called " Windows Form Designer generated code ".

There are also many classes that aren't controls or components but that can be created in code and have their properties modified and events handled during run time. The System.Net.Sockets.Socket class is an example.

For all classes that expose properties, you can "control" or modify that property through code. For example "TextBox1.BackColor = Color.WhiteSmoke" will change the BackColor of TextBox1 to WhiteSmoke during run time. You can also create event handlers for all classes that expose events. If you create (instantiate) the class through code, you would want to declare the instance using the WithEvents keyword.

So to answer your question finally; I don't believe there is a standard component for any sockets class (I may be wrong) but there are third party components available.
 
Hi,
thanks a lot for the answer. Now i get the point a bit more.
As you told me about the WithEvents keyword, i tried it out:

Private WithEvents test As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

But this doesn't work: it underlines the word test, and has as tooltip 'WithEvents variable does not raise any events'...

What does this mean, and how can i fix it, or is it just because there are no events for the socket class?


Thanks a lot
 
Back
Top