System.net.sockets (VB6'er - new to .Net)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • com64

    System.net.sockets (VB6'er - new to .Net)

    Hey all,

    I'm a casual/hobby programmer who's always used VB6. I'm trying out VB 2008
    express edition now. I understand a few basic concepts about .Net, but am
    doing this by myself with no more help than Google.

    I dont want to do anything fancy, just connect 2 machines to chat and play
    chess. I used the Winsock control in VB6, and have spent the last 4 hours
    or so googling to the conclusion that it's been replaced (?) with namespace
    System.Net.Sock ets...

    Every tutorial/help file I've found online has looked as if you needed 6
    months .Net experience before you could even BEGIN to understand it. I've
    gotten this far, but whenever I run this code the program freezes up until
    it gives a 'no response' error (not expecting a response at this point in
    time). Is there any .Net equivalent to DoEvents() ?

    Thanks in advance for any help/advice :0)



    On Error GoTo erra

    Dim hostEntry As IPHostEntry = Nothing
    Dim server As String = txtIP.Text
    Dim port As Integer = Int(txtPort.Tex t)

    ' Get host related information.
    hostEntry = Dns.GetHostEntr y(server)

    ' Loop through the AddressList to obtain the supported
    AddressFamily. This is to avoid
    ' an exception that occurs when the host IP Address is not
    compatible with the address family
    ' (typical in the IPv6 case).
    Dim address As IPAddress

    For Each address In hostEntry.Addre ssList
    Dim endPoint As New IPEndPoint(addr ess, port)
    Dim sck As New Socket(endPoint .AddressFamily, SocketType.Stre am,
    ProtocolType.Tc p)
    sck.Connect(end Point)
    Next address
    erra:
    errMsg(Err.Numb er & " - " & Err.Description )

  • Mr. Arnold

    #2
    Re: System.net.sock ets (VB6'er - new to .Net)


    "com64" <br4inz@orcon.n et.nzwrote in message
    news:634F7F27-B20E-44AF-8246-9D6643410A5F@mi crosoft.com...
    Every tutorial/help file I've found online has looked as if you needed 6
    months .Net experience before you could even BEGIN to understand it. I've
    gotten this far, but whenever I run this code the program freezes up until
    it gives a 'no response' error (not expecting a response at this point in
    time). Is there any .Net equivalent to DoEvents() ?
    >
    I don't know if it applies to your code situation.

    System.Windows. Forms.Applicati on.DoEvents()

    Comment

    • Joergen Bech

      #3
      Re: System.net.sock ets (VB6'er - new to .Net)


      Aside from the sockets stuff, you might want to forget everything you
      ever learned about On Error Goto/Resume and start using SEH
      (Structured Exception Handling):


      As for the evil DoEvents statement, this was covered in the recent
      recent thread with the subject "Long Process".

      Regards,

      Joergen Bech



      On Mon, 26 May 2008 22:05:03 +1200, "com64" <br4inz@orcon.n et.nz>
      wrote:
      >Hey all,
      >
      >I'm a casual/hobby programmer who's always used VB6. I'm trying out VB 2008
      >express edition now. I understand a few basic concepts about .Net, but am
      >doing this by myself with no more help than Google.
      >
      >I dont want to do anything fancy, just connect 2 machines to chat and play
      >chess. I used the Winsock control in VB6, and have spent the last 4 hours
      >or so googling to the conclusion that it's been replaced (?) with namespace
      >System.Net.Soc kets...
      >
      >Every tutorial/help file I've found online has looked as if you needed 6
      >months .Net experience before you could even BEGIN to understand it. I've
      >gotten this far, but whenever I run this code the program freezes up until
      >it gives a 'no response' error (not expecting a response at this point in
      >time). Is there any .Net equivalent to DoEvents() ?
      >
      >Thanks in advance for any help/advice :0)
      >
      >
      >
      On Error GoTo erra
      >
      Dim hostEntry As IPHostEntry = Nothing
      Dim server As String = txtIP.Text
      Dim port As Integer = Int(txtPort.Tex t)
      >
      ' Get host related information.
      hostEntry = Dns.GetHostEntr y(server)
      >
      ' Loop through the AddressList to obtain the supported
      >AddressFamil y. This is to avoid
      ' an exception that occurs when the host IP Address is not
      >compatible with the address family
      ' (typical in the IPv6 case).
      Dim address As IPAddress
      >
      For Each address In hostEntry.Addre ssList
      Dim endPoint As New IPEndPoint(addr ess, port)
      Dim sck As New Socket(endPoint .AddressFamily, SocketType.Stre am,
      >ProtocolType.T cp)
      sck.Connect(end Point)
      Next address
      >erra:
      errMsg(Err.Numb er & " - " & Err.Description )

      Comment

      Working...