ServerSockets with ClientSocket as TCPSockets

Hi, I have seen the ServerSocket Server and Client examples. I have made the server-client successfully connected with each other. But I have a problem here, how do i sent specific data to target client? I was able to pass info from Client to server but not Server to Target Client.

Before i was using serversockets i was using TCPsockets with Threads therefore I could like tcpsocket(index).write some msg
but for serversockets i tried clientsocket(mnum).write but the constructor is saying expected ptr instead of clientsocket.

the constructor : Constructor(mnum as integer)

I have notice ServerSockets created 12 ClientSockets
But how do i call each one?

In TCPSocket() i could just put the array num. but this is not in that form only way I can differentiate is the parameters inside mnum.

Any examples of how ServerSockets to write msgs? to single Client?

The server socket hands the connection to one of it’s client sockets. All the events (data) for that client connection fire inside the client socket that happened to get the connection when it came in. There is no need to specify which one as that decision is made by the server socket when it assigns a client socket to a new connection.

You only need one server socket on a port. All clients will connect to the same port, and as they connect the server socket will assign them a client socket.

Hopefully that makes sense, if not feel free to follow up.

Use ServerSocket.ActiveConnections to get an array of active sockets. Search through it to find the one you want (based on some data you’re storing in the clientsocket).

Great thanks. I understand now. but 1 last problem

[quote] dim i as integer
for i =0 to main.listbox1.listcount
try
if TCP(i).mnum=val(index) then
TCP(i).write sendinitialinfo
end if
end try

next i
[/quote]

the problem is here i cant get TCP(i).mnum <-dont exist
the property mnum can be found in ClientSocket but can’t get pass to TCP() or is there a way to get my variable

Thanks

You must type-cast the array items to your custom class.

if ClientSocket(TCP(i)).mnum = val(index) then

Also, loop from 0 to listbox1.listcount-1. Listcount itself is out of bounds.

Thanks alot!! It works . I used Clientsocket.handler instead