serversocket sendmessage to one client

// ServerSocketServerTest.xojo_binary_project


I use serversocket example all is good, client connect, disconnect, reveive message from client etc BUT…

I can juste respond to one client when i receive message from him.

if i want send message to one client i don’t know how.

example : i have 5 actives connexions… sockets 1,2,3,4,5

I want to send message on sockets 3

all my syntax don’t works.

Are you responding to a message from the same socket? That should be part of the TCPSocket subclass.

Yes i can respond to a message but my problem is when i want send message first.
I don’t know syntax to find socket in this example

if i would serversocket like chat for example, i cant receive and read message from shipper but I can’t send this private message because i can’t find socket recipient

You would loop through your serversocket.activeconnections, find the recipient and write through that socket. You can cast the activeconnections to your subclassed tcpsocket to address properties of the subclass.

hello wayne,

I just testing this when you write your message
I have to resolve problem because socketID is different of the ID of activeconnections
I’ll be back in few minutes thanks

it seem works but i need see if 2 clients are over same router
their remote ip are same
i have to know who is who

Add a user id to your subclassed tcpsocket.

oups …do you have a small example ? ?

I’m using easytcpsocket in serversocket

I did create proprety userid name etc

but i can’t access to it by activeconnections
addsocket function of serversocket create tcpsocket

i did this
Dim ret As EasyTCPSocket = New ClientforserveurEasyTcpSocket( MessageList, mCurrentSocket )

mCurrentSocket = mCurrentSocket + 1

ClientforserveurEasyTcpSocket is my easytcpsocket subclass with propreties

when i retreive connections like this
dim sock() as TCPSocket = mainserversocket.ActiveConnections
for i as integer = 0 to UBound(MainServerSocket.ActiveConnections)
sock(i)… => only propreties of tcpsocket , not my subclass easytcpsocket

Look up “casting” in the docs.

sock() as TCPSocket = mainserversocket.ActiveConnections
for i as integer = 0 to UBound(sock)   // use the snapshot you got here, 
                                     // don't go back to the serversocket, the list could have changed
    ClientforserveurEasyTcpSocket(sock(i)).username ...   // cast as your subclass

that is what I need
I’m stupid some times … I did this with delphi many times
thanks a lot…