Connection error
Connection error
Connection error
Connection error
Connection error
Connection error Connection error Connection error Connection error Connection error Connection error Connection error Connection error
Connection error Connection error
Connection error
Go Back  Xtreme Visual Basic Talk > > > Connection error


Reply
 
Thread Tools Display Modes
  #1  
Old 01-15-2011, 05:40 PM
1246 1246 is offline
Newcomer
 
Join Date: Jul 2010
Posts: 6
Default Connection error


Hello.
I am having an error in my server-client application where the first connect attempt is successful but the second is not.

Server code:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Not serving Then
            Dim slots As Integer = CInt(Replace(TextBox1.Text, " ", Nothing))
            If IsNumeric(slots) Then
                If slots > 0 And slots < 11 Then
                    serving = True
                    Button1.Text = "Serving..."
                    max_players = slots
                    Dim port As Integer = 21760
                    ReDim tcp_client(max_players)
                    Dim thread As New System.Threading.Thread(AddressOf Listen)
                    thread.IsBackground = True
                    thread.Start()
                End If
            End If
        End If

    End Sub

    Dim port As Integer = 21760
    Dim number As Integer = 0

    Private Sub Listen(ByVal index As Object)

        Do Until number = max_players -1
            Try
                tcp_listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, port)
                tcp_listener.Start()
                tcp_client(number) = tcp_listener.AcceptTcpClient
                tcp_listener.Stop()
                Dim data As String = "connection1|"
                Dim stream_writer As New System.IO.StreamWriter(tcp_client(number).GetStream)
                stream_writer.Write(data)
                stream_writer.Flush()
                tcp_client(number).GetStream.BeginRead(readBuffer, 0, 255, AddressOf Data_Arrival, Nothing)
                port = port + 1
                number = number + 1
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Loop

    End Sub

Client code:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Not connecting Then
            connecting = True
            Button1.Text = "Connecting..."
            TextBox1.ReadOnly = True
            username = TextBox1.Text
            Dim thread As New System.Threading.Thread(AddressOf Connect)
            thread.IsBackground = True
            thread.Start(current_port)
            Timer4.Start()
        End If

    End Sub

    Private Sub Connect(ByVal port As Object)

        Try
            current_port = CInt(port)
            tcp_client = New System.Net.Sockets.TcpClient("ip.ip.ip.ip", CInt(port))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

If you need any further info just ask.
Reply With Quote
  #2  
Old 01-17-2011, 07:47 AM
Orca44 Orca44 is offline
Centurion
 
Join Date: Nov 2004
Location: Cape Town, South Africa
Posts: 124
Default

Can you give more information regarding the failure of the second connection attempt?
I assume an exception is thrown, but what is the type and message of the exception?

Last edited by Orca44; 01-18-2011 at 12:22 AM.
Reply With Quote
  #3  
Old 01-17-2011, 06:02 PM
1246 1246 is offline
Newcomer
 
Join Date: Jul 2010
Posts: 6
Default

Nevermind. I just fixed it myself. Thanks anyway.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Connection error
Connection error
Connection error Connection error
Connection error
Connection error
Connection error Connection error Connection error Connection error Connection error Connection error Connection error
Connection error
Connection error
 
Connection error
Connection error
 
-->