In VB6 we used Winsock control, how to do this in VB.net? 
Author Message
 In VB6 we used Winsock control, how to do this in VB.net?

I have a sample VB6 app that uses Winsock control to talk to a device.

How do I do this in VB.net?\
Thanks for any advice

Here is some of the vb6 code.

' Connect to device
Private Sub NativeConn_Click()
ASCII = False
Native = True
If NativeConn.Caption = "Connect" Then
        NativeConn.Caption = "Connecting ..."
        DoEvents
        Winsock1.RemoteHost = IPText.Text
        Winsock1.RemotePort = 23
        Winsock1.connect
        NativeTimer.Interval = 2000
        NativeTimer.Enabled = True
        bWaiting = True
        Do While bWaiting
            DoEvents
        Loop
        If Not bConnect Then
            Winsock1.Close
            Exit Sub
        End If
        NativeConn.Caption = "Disconnect"
        Winsock1.SendData logintext.Text & Chr(13) & Chr(10) 'admin login
for ip address entered
        bWaiting = True
        Do While bWaiting
            DoEvents
        Loop
        Winsock1.SendData passwordtext.Text & Chr(13) & Chr(10) ' password
for ip address entered
        bWaiting = True
        Do While bWaiting
            DoEvents
        Loop
        NativeCommand.Enabled = True
        NativeCommand.SelStart = 0
        NativeCommand.SelLength = Len(Reply.Text)
    Else
        Winsock1.Close
        bConnect = False
        Native = False
        Reply.Text = "Connection Closed"
        NativeCommand.Enabled = False
    End If
End Sub

' Send command to device
Private Sub NativeCommand_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then 'if the Return key on the keyboard was pressed
then....
       bNewData = True
       If Native = True Then
        Winsock1.SendData NativeCommand.Text & Chr(13) & Chr(10)
        bWaiting = True
        Do While bWaiting
            DoEvents ' process other events coming in
        Loop
        End If
End If
End Sub



Sun, 30 Jan 2005 23:26:09 GMT  
 In VB6 we used Winsock control, how to do this in VB.net?
Hi,
Here is a simple piece of code to get you started
Shawn

Option Strict On
Option Explicit On
'***************************************************************
'* 24July2002
'* Shawn Shelton
'* This will attemtp a socket connection to check for the existence
'* of a server
'***************************************************************
Imports System.IO
Imports System.Net.Sockets

Module CheckForServer
        Public Function OpenSocket(ByVal server As String, ByVal Port As Short)
As Boolean
                Dim tcpClient As New System.Net.Sockets.TcpClient()
                Dim reader As StreamReader
                Dim buffer As String
                Try
                        tcpClient.Connect(server, Port)
                        reader = New StreamReader(tcpClient.GetStream())
                        buffer = reader.ReadLine()
                        reader.Close()
                        OpenSocket = True
                Catch ex As Exception
                        OpenSocket = False
                End Try
        End Function
End Module

Quote:

> I have a sample VB6 app that uses Winsock control to talk to a device.

> How do I do this in VB.net?\
> Thanks for any advice

> Here is some of the vb6 code.

> ' Connect to device
> Private Sub NativeConn_Click()
> ASCII = False
> Native = True
> If NativeConn.Caption = "Connect" Then
>         NativeConn.Caption = "Connecting ..."
>         DoEvents
>         Winsock1.RemoteHost = IPText.Text
>         Winsock1.RemotePort = 23
>         Winsock1.connect
>         NativeTimer.Interval = 2000
>         NativeTimer.Enabled = True
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         If Not bConnect Then
>             Winsock1.Close
>             Exit Sub
>         End If
>         NativeConn.Caption = "Disconnect"
>         Winsock1.SendData logintext.Text & Chr(13) & Chr(10) 'admin login
> for ip address entered
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         Winsock1.SendData passwordtext.Text & Chr(13) & Chr(10) ' password
> for ip address entered
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         NativeCommand.Enabled = True
>         NativeCommand.SelStart = 0
>         NativeCommand.SelLength = Len(Reply.Text)
>     Else
>         Winsock1.Close
>         bConnect = False
>         Native = False
>         Reply.Text = "Connection Closed"
>         NativeCommand.Enabled = False
>     End If
> End Sub

> ' Send command to device
> Private Sub NativeCommand_KeyUp(KeyCode As Integer, Shift As Integer)
> If KeyCode = vbKeyReturn Then 'if the Return key on the keyboard was pressed
> then....
>        bNewData = True
>        If Native = True Then
>         Winsock1.SendData NativeCommand.Text & Chr(13) & Chr(10)
>         bWaiting = True
>         Do While bWaiting
>             DoEvents ' process other events coming in
>         Loop
>         End If
> End If
> End Sub

--
-----------------------
Shawn Shelton
IT Programmer Analyst
Academic User Services
Idaho State University
-----------------------


Mon, 31 Jan 2005 00:28:12 GMT  
 In VB6 we used Winsock control, how to do this in VB.net?
Take a look at the System.Net namespace.  It contains all of the classes for
handling this.  In particular System.Net.TCPClient.

HTH

David

Quote:

> I have a sample VB6 app that uses Winsock control to talk to a device.

> How do I do this in VB.net?\
> Thanks for any advice

> Here is some of the vb6 code.

> ' Connect to device
> Private Sub NativeConn_Click()
> ASCII = False
> Native = True
> If NativeConn.Caption = "Connect" Then
>         NativeConn.Caption = "Connecting ..."
>         DoEvents
>         Winsock1.RemoteHost = IPText.Text
>         Winsock1.RemotePort = 23
>         Winsock1.connect
>         NativeTimer.Interval = 2000
>         NativeTimer.Enabled = True
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         If Not bConnect Then
>             Winsock1.Close
>             Exit Sub
>         End If
>         NativeConn.Caption = "Disconnect"
>         Winsock1.SendData logintext.Text & Chr(13) & Chr(10) 'admin login
> for ip address entered
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         Winsock1.SendData passwordtext.Text & Chr(13) & Chr(10) ' password
> for ip address entered
>         bWaiting = True
>         Do While bWaiting
>             DoEvents
>         Loop
>         NativeCommand.Enabled = True
>         NativeCommand.SelStart = 0
>         NativeCommand.SelLength = Len(Reply.Text)
>     Else
>         Winsock1.Close
>         bConnect = False
>         Native = False
>         Reply.Text = "Connection Closed"
>         NativeCommand.Enabled = False
>     End If
> End Sub

> ' Send command to device
> Private Sub NativeCommand_KeyUp(KeyCode As Integer, Shift As Integer)
> If KeyCode = vbKeyReturn Then 'if the Return key on the keyboard was
pressed
> then....
>        bNewData = True
>        If Native = True Then
>         Winsock1.SendData NativeCommand.Text & Chr(13) & Chr(10)
>         bWaiting = True
>         Do While bWaiting
>             DoEvents ' process other events coming in
>         Loop
>         End If
> End If
> End Sub



Mon, 31 Jan 2005 00:06:13 GMT  
 In VB6 we used Winsock control, how to do this in VB.net?
This works except...

The tcpClient.Connect(server,port) takes about 20 seconds to return to the
next line of code.
This is connecting to a device on port 23 (telnet) if that matters.

I launched telnet on this win2000 box just to make sure it wasn't a network
setting.  It instantly responds to an  open of the ip address.

Any ideas on why the response would be so slow?

Thanks

Chris



Quote:
> Hi,
> Here is a simple piece of code to get you started
> Shawn

> Option Strict On
> Option Explicit On
> '***************************************************************
> '* 24July2002
> '* Shawn Shelton
> '* This will attemtp a socket connection to check for the existence
> '* of a server
> '***************************************************************
> Imports System.IO
> Imports System.Net.Sockets

> Module CheckForServer
> Public Function OpenSocket(ByVal server As String, ByVal Port As Short)
> As Boolean
> Dim tcpClient As New System.Net.Sockets.TcpClient()
> Dim reader As StreamReader
> Dim buffer As String
> Try
> tcpClient.Connect(server, Port)
> reader = New StreamReader(tcpClient.GetStream())
> buffer = reader.ReadLine()
> reader.Close()
> OpenSocket = True
> Catch ex As Exception
> OpenSocket = False
> End Try
> End Function
> End Module


> > I have a sample VB6 app that uses Winsock control to talk to a device.

> > How do I do this in VB.net?\
> > Thanks for any advice

> > Here is some of the vb6 code.

> > ' Connect to device
> > Private Sub NativeConn_Click()
> > ASCII = False
> > Native = True
> > If NativeConn.Caption = "Connect" Then
> >         NativeConn.Caption = "Connecting ..."
> >         DoEvents
> >         Winsock1.RemoteHost = IPText.Text
> >         Winsock1.RemotePort = 23
> >         Winsock1.connect
> >         NativeTimer.Interval = 2000
> >         NativeTimer.Enabled = True
> >         bWaiting = True
> >         Do While bWaiting
> >             DoEvents
> >         Loop
> >         If Not bConnect Then
> >             Winsock1.Close
> >             Exit Sub
> >         End If
> >         NativeConn.Caption = "Disconnect"
> >         Winsock1.SendData logintext.Text & Chr(13) & Chr(10) 'admin
login
> > for ip address entered
> >         bWaiting = True
> >         Do While bWaiting
> >             DoEvents
> >         Loop
> >         Winsock1.SendData passwordtext.Text & Chr(13) & Chr(10) '
password
> > for ip address entered
> >         bWaiting = True
> >         Do While bWaiting
> >             DoEvents
> >         Loop
> >         NativeCommand.Enabled = True
> >         NativeCommand.SelStart = 0
> >         NativeCommand.SelLength = Len(Reply.Text)
> >     Else
> >         Winsock1.Close
> >         bConnect = False
> >         Native = False
> >         Reply.Text = "Connection Closed"
> >         NativeCommand.Enabled = False
> >     End If
> > End Sub

> > ' Send command to device
> > Private Sub NativeCommand_KeyUp(KeyCode As Integer, Shift As Integer)
> > If KeyCode = vbKeyReturn Then 'if the Return key on the keyboard was
pressed
> > then....
> >        bNewData = True
> >        If Native = True Then
> >         Winsock1.SendData NativeCommand.Text & Chr(13) & Chr(10)
> >         bWaiting = True
> >         Do While bWaiting
> >             DoEvents ' process other events coming in
> >         Loop
> >         End If
> > End If
> > End Sub

> --
> -----------------------
> Shawn Shelton
> IT Programmer Analyst
> Academic User Services
> Idaho State University
> -----------------------



Mon, 31 Jan 2005 03:24:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reconnection issue between Winsock Server(VB6) and TCP Client (VB.NET)

2. Help sending image files over the net using the Winsock Control

3. Custom Graph Control using PictureBox using VB.NET

4. winsock control in vb.net

5. Good articles on using .NET controls in VB6

6. VB.NET Microsoft WinSock Control, version 6.0 (SP5)

7. will vb.net support winsock control?

8. using .NET controls in VB6 projects

9. VB6 Winsock Control vs. Winsock API

10. VB6 Winsock Control vs. Winsock API

11. mailmerge with word97,2000,xp using vb.net,vb6

12. mailmerge with word97,2000,xp using vb6,vb.net

 

 
Powered by phpBB® Forum Software