kurt69
Well-known member
Hey howsit going?
Umm I'm trying to write some networking code, my application will have up to 8 concurrent connections, so it needs 8 sockets. I would rather not have to declare and write code for 8 sockets so I figured I'd try using some arrays, anyway here is what I've got. I don't have the chance to test it, so I would like to know if this would work before I do.
Umm I'm trying to write some networking code, my application will have up to 8 concurrent connections, so it needs 8 sockets. I would rather not have to declare and write code for 8 sockets so I figured I'd try using some arrays, anyway here is what I've got. I don't have the chance to test it, so I would like to know if this would work before I do.
VB.NET:
Public Sub lobbyHost()
Dim h As Integer
Dim tcpLstnr(8)
For h = 0 To UBound(tcpLstnr)
tcpLstnr(h) = New Sockets.TcpListener(IPAddress.Parse("127.0.0.1"), (11001 + h))
Do While hosted = True
tcpLstnr(h).Start()
If tcpLstnr(h).Pending = True Then
Try
Dim tcpCntrl As TcpClient = tcpLstnr(h).AcceptTcpClient()
tcpCntrl.NoDelay = True
tcpCntrl.LingerState.Enabled = False
Dim tcpStrm As NetworkStream = tcpCntrl.GetStream
Dim bytes(1024) As [Byte]
Dim rcvData As [String]
rcvData = Nothing
Dim i As Int32
While (i <> 0)
rcvData = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
i = tcpStrm.Read(bytes, 0, bytes.Length)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
Loop
Next
End Sub