|
-
Jun 27th, 2005, 01:37 PM
#1
Thread Starter
New Member
winsock with .NET
I have a friend that sent me a little chat program using winsock.
So, I started working on a little program as well.
His program is in VB 6, and I have VB.NET.
I got the control to work with my .NET environment, but I have noticed that a few things are different in .NET, and have been giving me tons of problems.
for example
VB Code:
Private Sub winsock_ConnectionRequest(ByVal requestID As Long)
This is the VB6 ConnectionRequest sub.
When I choose my winsock control, and find ConnectionRequest it creates this..
VB Code:
Private Sub winsock_ConnectionRequest(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles winsock.ConnectionRequest
I've seen winsock.Accept requestID all over the place, but this is an error, obviously because requestID isn't defined in the sub definition. So I tried to use sender. Also, when I do this, Visual Studio.NET changes the command to winsock.Accept(sender). I dont know if this is wrong or not, but it does not work.
As of right now I'm sitting at a rather nasty error: "Exception has been thrown by the target of an invocation." This comes up from this code...
VB Code:
Try
winsock.Accept(sender)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
What am I doing wrong? or where can I find a .NET example of how to use winsock?
-
Jun 27th, 2005, 07:37 PM
#2
Lively Member
Re: winsock with .NET
First of all, people will tell you how bad it is to use OCX controls in .NET. They work, but it is considered a bad practice, since .NET plans to escape all that mess.
However, Microsoft has not presented us with anything as useful as winsock in .NET, and only a few client-based classes exist that implement .NET sockets, and server apps are even fewer.
Anyway, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent looks like what you need to use. Just so you know, Sender is a variable that the event passes which refers directly to your Winsock object. If you put winsock.accept(blah), sender.accept(blah) would do the same.
I assume the "e" variable contains what you need. Just try typing in winsock.accept(e.) - when you type the period after the e, some methods/properties in e can be selected. I don't know how that works with it, but hopefully it will just be something like e.RequestID!
-
Jun 27th, 2005, 08:17 PM
#3
Re: winsock with .NET
Correct, there is no Windsock control in .NET. You need to re-write most of the app that your friend sent you. It will not convert
correctly, at least 99.9% of the time. Your almost always better off re-writting the old VB6 apps in pure .NET
Check out the System.Net.Sockets.NetworkStream namespace. There is a GetStream function that can use with the System.IO.StreamWritter
object to read data from the incoming stream.
Also, the System.Net.Sockets.TcpClient & Listener 
Ps, you might get a better response having the thread moved to VB.NET or post a link to this thread.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 27th, 2005, 08:23 PM
#4
Re: winsock with .NET
Here is a sample senddata procedure in .NET. No COM control needed.
VB Code:
Private client As TcpClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
client = New TcpClient("localhost", PORT_NUM)
'Blah, blah, blah...
'...
End Sub
'Use a StreamWriter to send a message to server.
Private Sub SendData(ByVal data As String)
Dim writer As New IO.StreamWriter(client.GetStream)
writer.Write(data & vbCr)
writer.Flush()
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|