?
Solved

Server Sockets

Posted on 1998-06-25
11
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Author Comment

by:bbreaux
ID: 1355752
Edited text of question
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1355753
bbreaux

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

Later
BoRiS

0
 

Expert Comment

by:fromager
ID: 1355754
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bbreaux
ID: 1355755
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 300 total points
ID: 1355756
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
 

Author Comment

by:bbreaux
ID: 1355757
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
ID: 1355758
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
ID: 1355759
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
ID: 1355760
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
ID: 1355761
I get an error when i use Broadcastmessage

undeclared identifier

0
 

Author Comment

by:bbreaux
ID: 1355762
i got it working thanks for the help
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

741 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