Results 1 to 8 of 8

Thread: Winsock Help!

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Location
    London
    Posts
    7

    Resolved Winsock Help!

    Hi everyone, first i will explain my set up:

    Winsock Program as Client

    Connects to my embedded PIC program, which is C code with a tcp/ip stack.

    I can get them to connect but it will only work once.

    The second time i get the run time error stating that:

    socket not bound, invalid address or listen is not invoked prior to accept.

    I am guessing there is a problem with the socket still being open.

    I am unsure whether it is from my V Basic code or the c code?

    Here is my VB Code:

    VB Code:
    1. ' initialize variables
    2. Private Sub Form_Load()
    3.    
    4.    
    5.     txtRemoteIpAddress = "192.168.0.20"
    6.     txtRemotePort = "13"
    7.     txtSocketStatus = SocketStatus(tcpClient.State)
    8.     txtLocalPort = tcpClient.LocalPort
    9.     txtLocalIpAddress = tcpClient.LocalIP
    10.     txtLocalHostName = tcpClient.LocalHostName
    11.  
    12.        
    13. End Sub
    14.  
    15.  
    16.  
    17. ' operator wants to connect to the server
    18. Private Sub cmdConnect_Click()
    19.     If (tcpClient.State = sckClosed) Then
    20.         ' Invoke the Connect method to initiate a connection.
    21.      
    22.         tcpClient.RemotePort = txtRemotePort
    23.         tcpClient.RemoteHost = txtRemoteIpAddress
    24.         tcpClient.Connect
    25.         txtRemoteHostName = tcpClient.RemoteHost
    26.     Else
    27.         MsgBox "ERROR: socket is not closed.  Socket must be closed before opening a new connection"
    28.     End If
    29. End Sub
    30.  
    31.  
    32.  
    33. Private Sub cmdDisconnect_Click()
    34. 'Disconnect from ClientProcedure
    35.  
    36. ' operator wants to exit the program
    37.  
    38.     tcpClient.Close
    39.     End
    40. End Sub
    41.  
    42.  
    43.  
    44. ' the server disconnected the connection
    45. Private Sub tcpClient_Close()
    46.     tcpClient.Close
    47. End Sub
    48.  
    49. ' the server sent us data
    50. Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
    51.     Dim strData As String
    52.    
    53.     tcpClient.GetData strData, vbString
    54.     txtOutput.Text = strData
    55. End Sub
    56.  
    57.  
    58. ' winsock control encountered an error
    59. Private Sub tcpClient_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    60.    Debug.Print "Server Error Number = " + Str(Number) + ",  Description = " + Description
    61.    txtSocketStatus = Description
    62. End Sub
    63.  
    64. ' this timer simply updates the status of the socket control on the display
    65. Private Sub Timer1_Timer()
    66.     txtSocketStatus = SocketStatus(tcpClient.State)
    67.     ' IF the socket is stuck in the closing or error states THEN close the socket to reset it
    68.     If ((tcpClient.State = sckClosing) Or (tcpClient.State = sckError)) Then
    69.         tcpClient.Close
    70.     End If
    71. End Sub


    Maybe i should have the vb code as the server and my embedded c code as the client?
    Last edited by stratty; Mar 23rd, 2005 at 12:15 PM.

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