Okay. First it appeared to work (I am able to connect to the sever) when I was improving my game, but when I tried to connect with another client it didn't connect.
Here's my server code:
Client 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..." Dim port As Integer = 21760 max_players = slots ReDim tcp_listener(max_players) ReDim tcp_client(max_players) For a As Integer = 0 To max_players - 1 tcp_listener(a) = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, port) tcp_listener(a).Start() port = port + 1 Timer1.Start() Timer5.Start() Next Dim thread As New System.Threading.Thread(AddressOf Listen) thread.IsBackground = True thread.Start() Else MsgBox("The slots number must be between 1 and 10.", MsgBoxStyle.Critical, "Error") End If Else MsgBox("The slots number must be a number.", MsgBoxStyle.Critical, "Error") End If End If End Sub Private Sub Listen(ByVal index As Object) Do Try tcp_client(CInt(index)) = tcp_listener(CInt(index)).AcceptTcpClient tcp_listener(CInt(index)).Stop() Dim data As String = "connection1|" Dim stream_writer As New System.IO.StreamWriter(tcp_client(CInt(index)).GetStream) stream_writer.Write(data) stream_writer.Flush() tcp_client(CInt(index)).GetStream.BeginRead(readBuffer, 0, 255, AddressOf Data_Arrival, Nothing) Exit Sub Catch ex As Exception MsgBox(ex.Message) End Try Loop End Sub
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