Book recommendations?

I just bought "Network Programming in .NET with C# and Visual Basic .NET" because of a recommendation here, but I got the book and found out that it's apparently in the wrong version for what I'm using. I'm using Visual Studio 2005 Professional, and I got syntax errors when I tried using some of the code in the book. The book looks like it's exactly what I want except for the incompatibility. Does anyone have any recommendations for books that teach socket and network programming in VB 2005 Thanks.

Answer this question

Book recommendations?

  • Dave.H

    I tried to enter the code to make a Layer 3 network tap. Today, I got it working without the errors I had before. I ran into one problem though, that prevented me from running it, and I don't understand the error.

    System.InvalidOperationException was unhandled
    Message="Cross-thread operation not valid: Control 'lbPackets' accessed from a thread other than the thread it was created on."

    So do you still have this issue What this means is that you are trying to update controls on a form from a
    thread that is used to callback your Callback function. If you lookinto MSDN there are specific examples of
    how you can fix this.



  • kkting

    Eventhough it is based on 1.1 version, the are very few changes at the
    socket level. You could work around these issues by looking up
    in the msdn. There are no books on 2.0 yet that I know of.
    What exactly are the issues you are having

  • Kevin Farlee

    Thanks. I don't know enough to know what to look for to fix this though. I think the error might actually have a link to how to do that, so I'll check. Thank you for your help.
  • Brice FROMENTIN

    Another .net socket book out there is "Professional .NET Network Programming". It duplicates MSDN too much but has some decent content to get you started.

  • Max Iturra

    I tried to enter the code to make a Layer 3 network tap.  Today, I got it working without the errors I had before.  I ran into one problem though, that prevented me from running it, and I don't understand the error.

    System.InvalidOperationException was unhandled
      Message="Cross-thread operation not valid: Control 'lbPackets' accessed from a thread other than the thread it was created on."
     

     Here's my code:

    Imports System

    Imports System.Windows.Forms

    Imports System.Net.Sockets

    Imports System.Net

    Imports System.Threading

    Imports System.text

    Public Class Form1

    Public listener As Threading.Thread

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

    btnStart.Enabled = False

    btnStop.Enabled = True

    listener = New Threading.Thread(New Threading.ThreadStart(AddressOf Run))

    listener.Start()

    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

    btnStart.Enabled = True

    btnStop.Enabled = False

    If Not listener Is Nothing Then

    listener.Abort()

    listener.Join()

    listener = Nothing

    End If

    End Sub

    Public Sub Run()

    Dim len_receive_buf As Integer = 4096

    Dim len_send_buf As Integer = 4096

    Dim receive_buf() As Byte = New Byte(len_receive_buf) {}

    Dim send_buf() As Byte = New Byte(len_send_buf) {}

    Dim cout_receive_bytes As Integer

    Dim socket As Net.Sockets.Socket = New _

    Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, _

    Net.Sockets.SocketType.Raw, Net.Sockets.ProtocolType.IP)

    socket.Blocking = False

    Dim IPHost As Net.IPHostEntry = _

    Net.Dns.GetHostByName(Net.Dns.GetHostName())

    socket.Bind(New _

    Net.IPEndPoint(Net.IPAddress.Parse _

    (IPHost.AddressList(0).ToString()), 0))

    socket.SetSocketOption(Net.Sockets.SocketOptionLevel.IP, _

    Net.Sockets.SocketOptionName.HeaderIncluded, 1)

    Dim bIN As Byte() = New Byte() {1, 0, 0, 0}

    Dim bOUT As Byte() = New Byte() {0, 0, 0, 0}

    Dim SIO_RCVALL As Integer = &H98000001

    Dim ret_code As Integer = socket.IOControl _

    (SIO_RCVALL, bIN, bOUT)

    Do

    Dim ar As IAsyncResult = socket.BeginReceive _

    (receive_buf, 0, _

    len_receive_buf, Net.Sockets.SocketFlags.None, Nothing, Me)

    cout_receive_bytes = socket.EndReceive(ar)

    Receive(receive_buf, cout_receive_bytes)

    Loop

    End Sub

    Public Sub Receive(ByVal buf As Byte(), ByVal len As Integer)

    If buf(9) = 6 Then

    lbPackets.Items.Add(Encoding.ASCII.getstring _

    (buf).replace(Chr(0), " "))

    End If

    End Sub

    End Class


  • nizzy8

    Well what errors are you getting

  • William R

    The issues I'm having are just that some of the syntax is obsolete, and I don't know enough about VB to know what's wrong or how to make it work with the new .NET. Visual Studio did give me help in letting me know how to change some of the syntax, but I'm not sure about all of it. I'd really like to keep the book though, if I can figure it out, because it's exactly what I need.
  • Book recommendations?