Solved

Server Sockets

Posted on 1998-06-25
11
169 Views
Last Modified: 2010-04-04
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
Comment
Question by:bbreaux
11 Comments
 

Author Comment

by:bbreaux
Comment Utility
Edited text of question
0
 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
bbreaux

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

Later
BoRiS

0
 

Expert Comment

by:fromager
Comment Utility
0
 

Author Comment

by:bbreaux
Comment Utility
yes i have look at the example but it doesnt allow for mutiplte connections only pier to pier
0
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:bbreaux
Comment Utility
I have a array or records
could i just asign the sockethandle to a varible in my record

example:
 
myrecoord.handle :=socket.sockethandle

0
 

Author Comment

by:bbreaux
Comment Utility
I have a array or records
could i just asign the sockethandle to a varible in my record

example:
 
myrecoord.handle :=socket.sockethandle

0
 

Author Comment

by:bbreaux
Comment Utility
that works great next to the fact i cant figure out how to loop over the list and send to that user
0
 
LVL 4

Expert Comment

by:d003303
Comment Utility
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
 

Author Comment

by:bbreaux
Comment Utility
I get an error when i use Broadcastmessage

undeclared identifier

0
 

Author Comment

by:bbreaux
Comment Utility
i got it working thanks for the help
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 73
FMX enumerated colours 2 70
Printing problem 2 72
Convert GUI app into console app for Win32 Env 5 55
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now