Results 1 to 8 of 8

Thread: Socket connected but send doesn't seem to work

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    6

    Socket connected but send doesn't seem to work

    I have an old vb6 desktop application which communicates with a mainframe server using socket (winsock 2) that i need to convert to .net. I found the small code which seems correct to me using System.Net.Socket. When running the console window just hang there showing blank.
    Code:
            Dim s As Socket = ConnectSocket(server, port)
    
            If s Is Nothing Then
                Return "Connection failed"
            End If
            ' Send request to the server.
    
            Dim numSent As Integer
            numSent = s.Send(bytesSent)
    
    
            Dim bytes As Int32
    
            Do
                bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
                Console.WriteLine(bytes.ToString())
    
            Loop While bytes > 0
    Here is the connect function
    Code:
    Private Function ConnectSocket(server As String, port As Integer) As Socket
            Dim s As Socket = Nothing
            Dim hostEntry As IPHostEntry = Nothing
    
            ' Get host related information.
            hostEntry = Dns.GetHostEntry(server)
    
            ' Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            ' an exception that occurs when the host host IP Address is not compatible with the address family
            ' (typical in the IPv6 case).
            Dim address As IPAddress
    
            For Each address In hostEntry.AddressList
                Dim endPoint As New IPEndPoint(address, port)
                Dim tempSocket As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
    
                tempSocket.Connect(endPoint)
    
                If tempSocket.Connected Then
                    s = tempSocket
                    Exit For
                End If
    
            Next address
    
            Return s
        End Function
    So I run wireshark on the port the app is communicating (port in the code above) I can see package sent and received with connectSocket, but no package is detected with s.Send(bytesSent). I wonder why.
    Last edited by flyingpan; Aug 26th, 2020 at 04:50 PM.

Tags for this Thread

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