• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Server Sockets

I'm working on this chat program using serversockets
I can get mutilple connetions to the server part but when i send a message from a client  i cant relay the message to the other connections.
How do i change to a different socket connection to send out  the message?
0
bbreaux
Asked:
bbreaux
1 Solution
 
bbreauxAuthor Commented:
Edited text of question
0
 
BoRiSCommented:
bbreaux

have you checked out the chat demo that comes with delphi...

Later
BoRiS

0
 
fromagerCommented:
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
bbreauxAuthor Commented:
yes i have look at the example but it doesnt allow for mutiplte connections only pier to pier
0
 
d003303Commented:
Yo,
you will have to hold a list of all connected clients that is updated in the OnClientConnect and OnClientDisconnect event handlers. Use AddObject(IntToStr(Socket.SocketHandle), Socket) to save the object in the string list. When a client disconnects, use Delete(IndexOfName(IntToStr(Socket.SocketHandle)) to remove him from the list.
To broadcast the incoming message, loop through the list and send all clients the message data (maybe you want to leave out the sender).

Slash/d003303
0
 
bbreauxAuthor Commented:
I have a array or records
could i just asign the sockethandle to a varible in my record

example:
 
myrecoord.handle :=socket.sockethandle

0
 
bbreauxAuthor Commented:
I have a array or records
could i just asign the sockethandle to a varible in my record

example:
 
myrecoord.handle :=socket.sockethandle

0
 
bbreauxAuthor Commented:
that works great next to the fact i cant figure out how to loop over the list and send to that user
0
 
d003303Commented:
You could also use an array of records for that. I recommend a string list because it can hold a variable amount of users at run-time. With the array, you are limited to the arrayy bounds that is set at compile-time.
Loop throug the list with
for index := 0 to UserList.Count - 1
 do BroadcastMessage(TSocket(UserList.Objects[index]), Message);
where BroadcastMessage would send the chat message. You can cast UserList.Objects[index] to the appropriate socket you received if you need to.

Slash/d003303
0
 
bbreauxAuthor Commented:
I get an error when i use Broadcastmessage

undeclared identifier

0
 
bbreauxAuthor Commented:
i got it working thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now