Let's say that I run this raw code. This is on a server side, the
server will wait for client connection request.
Private MyTcpListener As System.Net.Sock ets.TcpListener
Private MySocket As Socket
Dim MyPort as int32
MyPort = 1000
Dim ipHostInfo As IPHostEntry = Dns.GetHostByNa me(Dns.GetHostN ame()) Dim
MyIPAddress As IPAddress = ipHostInfo.Addr essList(0)
Dim localEndPoint As New IPEndPoint(MyIP Address, MyPort)
MyTcpListener = New Net.Sockets.MyT cpListener(loca lEndPoint)
MyTcpListener.S tart()
[...]
'Looping periodically on MyTcpListener to see if any client try to
' connect
If Not (MyTcpListener. Pending()) Then
Exit Sub
else
MySocket = MyTcpListener.A cceptSocket
End If
For a new connection MySocket will containt information about the new
client information (port, IP).
If I want many clients being able to connect to this server, do I have
to create an array of MySocket? Then any new accepted client would be
indexed (from i=0 to n, n=max connect allowed). That index would be
useful for me.
And I wouldn't have to care anymore with port number? Is that right?
How could I connect a "datareceiv e event" from any client?
Thanks you very much!
server will wait for client connection request.
Private MyTcpListener As System.Net.Sock ets.TcpListener
Private MySocket As Socket
Dim MyPort as int32
MyPort = 1000
Dim ipHostInfo As IPHostEntry = Dns.GetHostByNa me(Dns.GetHostN ame()) Dim
MyIPAddress As IPAddress = ipHostInfo.Addr essList(0)
Dim localEndPoint As New IPEndPoint(MyIP Address, MyPort)
MyTcpListener = New Net.Sockets.MyT cpListener(loca lEndPoint)
MyTcpListener.S tart()
[...]
'Looping periodically on MyTcpListener to see if any client try to
' connect
If Not (MyTcpListener. Pending()) Then
Exit Sub
else
MySocket = MyTcpListener.A cceptSocket
End If
For a new connection MySocket will containt information about the new
client information (port, IP).
If I want many clients being able to connect to this server, do I have
to create an array of MySocket? Then any new accepted client would be
indexed (from i=0 to n, n=max connect allowed). That index would be
useful for me.
And I wouldn't have to care anymore with port number? Is that right?
How could I connect a "datareceiv e event" from any client?
Thanks you very much!