Jump to content

Socket errors.


Recommended Posts

I am going to use this thread for help fixing all these socket errors.

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll

No connection could be made because the target machine actively refused it

    Sub connectCallback(asyncConnect As IAsyncResult)

Gets called by this sub:

Public Sub Connect()
        If Not PlayerSocket Is Nothing Then ' 174 & 292 modGeneral
                If PlayerSocket.Connected Or SckConnecting Then Exit Sub
                PlayerSocket = Nothing
            Catch ex As Exception

            End Try
        End If
        PlayerSocket = New TcpClient()
        PlayerSocket.ReceiveBufferSize = 4096
        PlayerSocket.SendBufferSize = 4096
        PlayerSocket.NoDelay = False
        ReDim asyncBuff(8192)
        PlayerSocket.BeginConnect(Options.Ip, Options.Port, New AsyncCallback(AddressOf connectCallback), PlayerSocket)
        SckConnecting = True
    End Sub

Which gets called by this sub.  It keeps checking if the server is open, then enables the Play button.  If I just ping the IP address it is always going to show that the server machine is available, not if the server program is actually running.

Private Sub tmrConnect_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tmrConnect.Tick
        Static i As Long
        If IsConnected() Then
            lblServerStatus.ForeColor = Color.Green
            lblServerStatus.Text = "Online"
            lblServerStatus.ForeColor = Color.Red
            i = i + 1
            If i = 5 Then
                lblServerStatus.Text = "Reconnecting"
                i = 0
                lblServerStatus.Text = "Offline"
            End If
        End If
    End Sub

I can ignore them, and the server works.  But I need to weed through all of these errors when all exceptions are turned on.

Link to comment
Share on other sites

This second error occurs when I hit the exit button.  The connection looks like it has been severed, but the server is still trying to access it:


A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll

Additional information: Cannot access a disposed object.

Sub OnReceive(ar As IAsyncResult)
            Dim byteAmt As Integer = myStream.EndRead(ar)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...