|
-
Jan 13th, 2008, 12:40 PM
#1
Thread Starter
Member
Multiple Clients?
What is the best way for a tcp server to accept multiple tcp clients? The clients have no way of knowing what ports are already used by the server. Is there some way to setup portforwarding on the server?
Last edited by qazwsx; Jan 13th, 2008 at 03:39 PM.
-
Jan 13th, 2008, 12:49 PM
#2
Frenzied Member
Re: Multiple Clients?
Well most servers use a constant port number such as 10000 or something like that. Then the user connects to the server's ip address and that port number. The port number may be in the program by default or available on the program/game's website.
-
Jan 13th, 2008, 01:44 PM
#3
Thread Starter
Member
Re: Multiple Clients?
I understand the constant port number. But if there are multiple clients can they all be connected on the same port?
-
Jan 13th, 2008, 02:03 PM
#4
-
Jan 13th, 2008, 02:31 PM
#5
Thread Starter
Member
Re: Multiple Clients?
Could you explain to me how to do that?
This is what I have so far:
Server
Code:
Dim client(9) As TcpClient
Dim server As TcpListener
Dim listthread As New System.Threading.Thread(AddressOf accept)
Sub createthread()
buttonstate(True)
Dim i As Integer
For i = 0 To client.Length - 1
client(i) = New TcpClient()
Next
server = New TcpListener(IPAddress.Any, 2999)
server.Start()
listthread.Start()
End Sub
Sub accept()
Dim j As Integer = 0
Dim i As Integer
While 1
For i = 0 To client.Length - 1
If client(i).Client.Connected Then
j = i
Exit For
End If
Next
Try
server.Start()
client(j) = server.AcceptTcpClient()
setcresults(client(j).Client.RemoteEndPoint.ToString & ": Connected")
Dim stream As NetworkStream = client(j).GetStream
Catch ex As Exception
MsgBox(ex.Message)
End Try
End While
End Sub
Client
Code:
Dim networkstream As System.Net.Sockets.NetworkStream
Dim tcpclient As New Net.Sockets.TcpClient()
Sub connect()
While 1
Try
Try
tcpclient.Connect("sccrstvn93.no-ip.org", 2999)
Catch ex As Exception
MsgBox(ex.Message)
End Try
While 1
networkstream = tcpclient.GetStream
acceptdata()
executecommand(clientdata)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End While
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|