Results 1 to 5 of 5

Thread: VB6 To VB.NET (Winsock)

  1. #1

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    VB6 To VB.NET (Winsock)

    Here is my current function which uses a Winsock control (on a seperate form) to connect to a server, send an HTTP Request, and recieve/handle the returned data:

    VB Code:
    1. Public Function GetHTTP(htype As HTTPType, strUrl As String, Optional strcookie As String, Optional strrefer As String, Optional strData As String, Optional GZIP As Boolean = True) As String
    2.     Dim strServer As String
    3.     Dim strPage As String
    4.     Dim header As String
    5.  
    6.     frmMain.sck1.Close
    7.     Connected = False
    8.  
    9.     If InStr(1, strUrl, "http://") Then
    10.         strUrl = Replace(strUrl, "http://", "")
    11.     End If
    12.  
    13.     iStart = InStr(6, strUrl, ".") + 4
    14.     strPage = Mid$(strUrl, iStart, (Len(strUrl) + 1) - iStart)
    15.     strServer = Replace(strUrl, strPage, "")
    16.     strPage = Replace(strPage, " ", "%20")
    17.     StrReturn = ""
    18.  
    19.     frmMain.sck1.Connect strServer, 80
    20.  
    21.     Do Until Connected = True Or frmMain.sck1.State = 9
    22.         DoEvents
    23.     Loop
    24.  
    25.     If frmMain.sck1.State = 9 Then
    26.         MsgBox "Error connecting to server!"
    27.         frmMain.sck1.Close
    28.         Exit Function
    29.     End If
    30.  
    31.     header = CreateHeader(htype, strServer, strPage, strcookie, strrefer, strData, GZIP) 'Creates an HTTP Request
    32.     frmMain.sck1.SendData header
    33.  
    34.     Do Until frmMain.sck1.State = 8
    35.         DoEvents
    36.     Loop
    37.  
    38.     lngPos = InStr(1, StrReturn, vbCrLf & vbCrLf)
    39.     If InStr(1, StrReturn, "text/html; charset=UTF-8" & vbNewLine & vbNewLine) Then
    40.     ' Future Handle '
    41.     ElseIf StrReturn <> "" And GZIP = True Then
    42.         Strheader = Left(StrReturn, lngPos - 1)
    43.         StrReturn = Right$(StrReturn, Len(StrReturn) - lngPos - 3)
    44.         StrReturn = DecompressGzipData(StrReturn, LenB(StrReturn))
    45.         StrReturn = Strheader & vbNewLine & vbNewLine & StrReturn
    46.     End If
    47.  
    48.     Connected = False
    49.     GetHTTP = StrReturn
    50.     glastpage = strUrl
    51.     frmMain.sck1.Close
    52. End Function

    I need to know the best method for doing what I did above in VB.NET. I know there are multiple ways of accessing the net through the language, but I prefer to stick with simple connecting to server, and retreiving data. Can anyone suggest the best method for doing this? And yes, I also need to handle GZIP Compressed data, in VB6 I have to use an external DLL, but I think it's possibly to do it internally in .NET.
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: VB6 To VB.NET (Winsock)

    Its not my area of expertise but you should be using the Sockets class and not the COM winsock control in .NET.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: VB6 To VB.NET (Winsock)

    The code I posted is VB6 code I want to convert to .NET code Does the Sockets class have similiar attributes to the winsock control? Enough so that I can imitate the above coding in .NET?
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713

    Re: VB6 To VB.NET (Winsock)

    What version are you running? 2003 or 2005?

    You have the System.Net, System.Net.Sockets, System.Net.NetworkInformation classes, all of which can do the same things as the windsock control but using different methods.


    in the 101 .NET Tutorial downloads there are examples for each version.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: VB6 To VB.NET (Winsock)

    I'm running 2005 Express Edition. I have seen a few of the different methods before and most of them were way to advanced for what I needed to do. I just want the simplest method of doing what winsock does in .NET. I would assume .NET sockets are alot faster then the COM control too, which is a plus. But i'll do a little more searching on System.Net.Socket.
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width