Winsock 6 control in VB.NET

K

kimiraikkonen

Hi,
As you know there's no mswinsck.ocx ActiveX control in VB.NET 2005 or
08 by default, but it exists in VB6. However i can add this old
control to my VB 2005 toolbox with no problem by extracting from VB6's
cabinets, but when using inside my project, i get some syntax problems
which runs fine in VB6. I do not want to go back VB6.

Is it healthy and supported using mswinsck.ocx Winsock control in
VB.NET projects?

And is System.Net.Sockets the unique alternative for this Winsock
control and is it completely equilavent?

Thanks
 
T

Tom Shelton

Hi,
As you know there's no mswinsck.ocx ActiveX control in VB.NET 2005 or
08 by default, but it exists in VB6. However i can add this old
control to my VB 2005 toolbox with no problem by extracting from VB6's
cabinets, but when using inside my project, i get some syntax problems
which runs fine in VB6. I do not want to go back VB6.

Is it healthy and supported using mswinsck.ocx Winsock control in
VB.NET projects?

And is System.Net.Sockets the unique alternative for this Winsock
control and is it completely equilavent?

Thanks

You want to use System.Net.Sockets. The winsock control sucked in VB6,
and it sucks even worse in .NET ;)
 
K

kimiraikkonen

You want to use System.Net.Sockets.  The winsock control sucked in VB6,
and it sucks even worse in .NET ;)

Dear Tom, Thanks for the information. However actually my intention
was to program a small application that consist of 2 parts, server and
client for sending any file over the WAN, not LAN. Do you have a
simple code that demonstrates that on .NET using sockets class?

Thanks

Onur Güzel
 
T

Tom Shelton

Dear Tom, Thanks for the information. However actually my intention
was to program a small application that consist of 2 parts, server and
client for sending any file over the WAN, not LAN. Do you have a
simple code that demonstrates that on .NET using sockets class?

Thanks

Onur Güzel

Sure... MS has a fairly good set of examples. On both sync and async
usage (start here):

http://msdn2.microsoft.com/en-us/library/b6xa24z5.aspx

There are articles off of here, for both server and client usage.
 
K

kimiraikkonen

Sure...  MS has a fairly good set of examples.  On both sync and async
usage (start here):

http://msdn2.microsoft.com/en-us/library/b6xa24z5.aspx

There are articles off of here, for both server and client usage.

Thanks, i'll check and there are similar samples in 101 samples page.
I saw some good Winsock 6 samples using mswinsck.ocx but it's hard to
get the working code in .NET environment, beleive. Maybe there's
a .NET wrapper for legacy Winsock 6, even it can be added to .NET
toolbox as ActiveX control, surprise.

Regards
 
K

kimiraikkonen

Thanks, i'll check and there are similar samples in 101 samples page.
I saw some goodWinsock6 samples using mswinsck.ocx but it's hard to
get the working code in .NET environment, beleive. Maybe there's
a .NET wrapper for legacyWinsock6, even it can be added to .NET
toolbox as ActiveX control, surprise.

Regards

Tom, to update, i added Winsock 6 ActiveX control (mswinsck.ocx) to
use in VB.NET to accomplish a basic chat operation on the same
machine(127.0.0.1) and here is an exception that Winsock 6 throws when
sending text string (data) from client to server:
"Exception from HRESULT: 0x800A9C46"

Full client code:

And it fails at:
"tcpClient.SendData(CStr(TextBox2.Text.ToString))" and unusing "CStr"
also made no difference.

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
tcpClient.RemotePort = 1001
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Try
tcpClient.RemoteHost = Trim(TextBox3.Text)
tcpClient.Connect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
tcpClient.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
If Not TextBox2.Text = "" Then
tcpClient.SendData(CStr(TextBox2.Text.ToString))
End If
End Sub

Private Sub tcpClient_DataArrival(ByVal sender As System.Object,
ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent)
Handles tcpClient.DataArrival
Dim strData As String
tcpClient.GetData(strData)
MsgBox(strData)

End Sub
End Class

Is it a coding error or because Winsock 6's behaviour in VB.NET?

Thanks
 
T

Tom Shelton

Tom, to update, i added Winsock 6 ActiveX control (mswinsck.ocx) to
use in VB.NET to accomplish a basic chat operation on the same
machine(127.0.0.1) and here is an exception that Winsock 6 throws when
sending text string (data) from client to server:
"Exception from HRESULT: 0x800A9C46"

Full client code:

And it fails at:
"tcpClient.SendData(CStr(TextBox2.Text.ToString))" and unusing "CStr"
also made no difference.

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
tcpClient.RemotePort = 1001
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Try
tcpClient.RemoteHost = Trim(TextBox3.Text)
tcpClient.Connect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
tcpClient.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
If Not TextBox2.Text = "" Then
tcpClient.SendData(CStr(TextBox2.Text.ToString))
End If
End Sub

Private Sub tcpClient_DataArrival(ByVal sender As System.Object,
ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent)
Handles tcpClient.DataArrival
Dim strData As String
tcpClient.GetData(strData)
MsgBox(strData)

End Sub
End Class

Is it a coding error or because Winsock 6's behaviour in VB.NET?

Thanks

To be completely honest, there are a number of reasons that I could not
even begin to answer this question... Starting with the fact, that I
didn't use the Winsock control in VB.CLASSIC - I always used the raw
winsock api for all of my socket communication - so, I really don't know
much about that particular control. Second, I don't have a copy of VB6
or it's documentation installed on any of my current systems. I long
ago abandoned VB of any flavor - and currently do all my work in C#.
And the last reason, is that I don't think you should even bother going
down this route - since the .NET framework as very good support of
tcp/ip communication (both asyncronous and syncronous) built in.

Maybe someone else here will be able to answer your question?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top