 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Lester Guest
|
Posted: Tue Jan 30, 2007 9:11 am Post subject: Chat server: referencing CERTAIN clients (connections) in IC |
|
|
Hello everyone, I'm kinda new to Delphi and especially to ICS.
I'm building a chat server using ICS's TWSocketThrdServer (descendant
of TWSocketServer), TCP protocol. I read about the Client[index] and
ClientCount property, so I can roll and send message to ALL the
clients if I need to.
However, there are cases when I need to send messages to CERTAIN
clients (one or two), and not necessarily the one that just sent data
to the server (thus firing onDataAvailable event). How can I reference
to certain clients? Should I store each client's pointer or something?
I need a reference to each client that would not change as long as the
chat server app is running. What would that be?
Let me rephrase it. One client sends a "private" message to another
client. So its message to the server actually contains the reference
to the other client. What could that reference be?
Thank you very much in advance!
Lester |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Tue Jan 30, 2007 6:15 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
you can form groups in the server, where each group is represented by
a structure of data and each structure stores the IDs of conexoes of
the usuarios that belong to the group
type group = class
name : String;
IDsUsers : TStrings;
end;
GroupUsers.name := 'room1';
procedure TForm1.ServerAccept(Sender: TObject; Socket:
TCustomWinSocket);
begin
Count := Count + 1;
GroupUsers.IDsUsers.Add(IntToStr(Count));
end;
for i := 0 to GroupUsers.IDsUsers.Count do begin
Server.Socket.Connections[StrToInt(GroupUsers.IDsUsers.Items[i].Text)].
SendText('Text Here');
end;
it makes a good management of the connections
the more things you to want to manage more complex will become the
structure of data
byebye |
|
| Back to top |
|
 |
Lester Guest
|
Posted: Wed Jan 31, 2007 12:18 am Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
Thank you Felipe, but I think you misunderstood me. Managing user
groups is the easier part. But finding ONE particular connection in
the connection pool, without looping through many of them, is a more
difficult one (at least for me).
Here is what I'm trying, my question is in the last line:
procedure TClientConnection.DataAvailable(
Sender: TObject;
Error : Word);
begin
userid := IntToStr(LongInt(self)) //<-- What exactly do I get
with this???
And later OTHER users could send messages to THIS user (whose ID is
saved in "userid" above):
procedure TfrmMain.sendToOne(theID: longint; thetext: string);
begin
TClientConnection(TObject(theID)).SendStr(thetext + #13#10); //<-
Can I do this???
end;
I was thinking about a similar solution. Would this work in the long
run? Will IntToStr(LongInt(ClientConnection)) provide a usable direct
reference to the connection?
Lester |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Wed Jan 31, 2007 6:50 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
with one ListBox where each index of elements are the ID of the
connections and the text is a nickname of person in the chat...
or in each text of the elements in the listbox you save with text::
IDConnection - NickName
With the mouse selectioning one element or search for nickname .. take
idconnection with StrToInt(Copy(ListBox1.Items[i].Text,1,Pos(' -
'+Nickname,ListBox1.Items[i].Text)));
This search in Thread Procedure not will stop the program
In the server is better save this datas in data structs .. will be
possible to save in file and find there. an the client program this
data will be in the visual components
type clients = class
IdConnection : Integer;
NickName : String;
next : ^clients; list of clients
last : ^clients;
end;
type ClassRoom = class
IDRoom : Integer;
ClientsList : clients;
end;
This not is the solution more easy .. but is with I like of to work.
Remember .. use threads for search in strings
Understand my words? .. excuse, my native language is portuguese :D
byebye |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Wed Jan 31, 2007 6:55 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
| Quote: | TClientConnection(TObject(theID)).SendStr(thetext + #13#10); //<-
|
Use Only SendStr(thetext); |
|
| Back to top |
|
 |
Lester Guest
|
Posted: Thu Feb 01, 2007 9:11 am Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
Thanks, it helps, but I still don't know how to get a unique ID that
references to the connection. Indexes in a list can change be time
(when someone logs out). I am interested a more direct reference that
I mentioned in my previous post. Could that be used to save each
connection's reference?
See, when a private message arrives to the chat server, it will
contain a reference to the target connection, it will be a number. But
a number of WHAT? It cannot be a list index, because that may change,
right? Can I just save in a TList the LongInt(TheConnectionObject) as
an ID to which I can refer later?
(My native language is Hungarian, by the way )
Thanks again!
Lester |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Fri Feb 02, 2007 2:32 am Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
I understand your doubt about index of connections ..we go to see if
now it decides :D
is inserted one element in the dinamic Array of connections all the
times that accepted server one connection.. Then this element has one
index [ i ].. with Socket.connections[i]... when one conexao will be
accepted in the server must be added the data of conexao in combobox
or one string-grid.. this combobox will go to grow together to the
vector of connections... when a disconnection to occur through the
ServerDiscconect(*) Event, then you can remove the element of combobox
or string-grid corresponding, therefore, both has same index [ i ]..
and automatically the last index will be readjusted in both the
structures why, despite of the static vector appearance, they are
dynamic lists.
Accept Event-> string-grid.Add(datas);
Disconnect Event -> if Socket.Connection[Index]."data" =
Socket."data" then string-grid.delete(Socket.index); .. the data can
be a instance or other member that can be compared.
as both indexs was deleteds in the connections vector and string-grid
datas.. and the amount of items are equals..the indexs in the both
"tables" (connections vector and string-grid datas) then both continue
compatible.
With OnClick in string-grid or combo-box of nickname in the chat the
index of stringgrid can be used ...
procedure StringGridClick(*);
begin
for i := 0 to StringGrid.Items.Count do begin
if StringGrid.Items[i].Selected then begin
ServerSocket.Connections[i].Sendtext(StringGrid.Items.Nickname.Text +
'text of edit1.text');
end;
end;
end;
The MIRC program use this technique - www.mirc.com ... observes the
component IdIRC of Pallete Indy .. www.indyproject.org
you try to make of this form  |
|
| Back to top |
|
 |
Lester Guest
|
Posted: Sun Feb 04, 2007 4:21 am Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
| Good point. That is the place to look. Thank you for your time! |
|
| Back to top |
|
 |
Lester Guest
|
Posted: Sun Feb 04, 2007 10:38 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
I'm sorry to realize that IdIRC is just a shell, not an
implementation, so there is not much to lear from there. So I need to
re-post my question. Still I have the feeling that you try to answer
another question, not mine. Here is how I want my server work:
(1) Client connects, and, upon connection, gets the entire list of
connected users from the server.
(2) IF client wants to send a private message, the message string
contains DIRECT reference to the targeted client, like:
FromName, TargetUserID, "This is the message text"
The client KNOWS the TargetUserID, because the server has sent it.
(3) Server receives the string above, knows to WHO it was sent to, and
sends out the message to the client (connection) referenced by
"TargetUserID"
Now my original question was, what this TargetUserID could be? If it
is any kind of index, it could either change by time, OR require the
server to ROLL over ALL the clients to find it. Now this is what I
dont want, because it is very time-consuming.
This is why I asked if LongInt(TClientConnection) could be used for
this. Wouls that be a reliable reference? Please see my code above
(jan. 30). Because when a new user connects, a new TClientConnection
is created by ICS, THEN I want to store its direct reference and let
the clients know it too.
I dont know where to go. It is not much ICS question, rather Delphi
question in general. |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Mon Feb 05, 2007 4:47 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
it forgives, had not understood the problem correctly
The ICS is used from sharing of connection with the InterNet, then if
the IP will be in the same band of local IP then the computer chooses
conexao of local net pra to send the data, case is different it sends
the data for conexao with the InterNet. 2 connections: 1 local net and
1 InterNet.
Now, I continue without understanding the problem to directly send the
data for a PC. It is enough uses the NAT <router> to execute this
task.
PC1 <--> Router1 <--> Router2 <--> PC2
PC3 <--> Router1
Router1 <--> Router2 <--> Router3 <-->PC6
Router1 -//- Router3 .......connection less
IP of PC1: 192.168.0.2
IP of PC2: 200.10.23.34
IP of PC6: 201.23.121.4
PC1 send data from Router1, this decides if IP is local or externet
and send the datas. If data is destined from PC6 this data will be
sended from Router2 and Router2 send from Router3, until arrive in
PC6.
Router2 receive the data and send from all routers, except Router1.
There is rules more complex, table of routes, best way, and more.
Routing, ICS less Routing not work - search the way, now understand
rigth ?
I will go one test in college now, bye bye! |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Mon Feb 05, 2007 4:52 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
now,
ICS (Internet Connection Sharing)
Chat server and ICS are different concepts  |
|
| Back to top |
|
 |
Lester Guest
|
Posted: Mon Feb 05, 2007 6:42 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
Internet Component Suite
http://www.overbyte.be/frame_index.html?redirTo=/products/ics.html
Chat server written in Delphi.
Clients connect to server, send private message to OTHER clients. The
reference (number?) to other client (connection) will be in message.
I dont know how to explain it better, it has nothing to do with
routers.
Just please answer the original question. |
|
| Back to top |
|
 |
felipemoraes Guest
|
Posted: Tue Feb 06, 2007 7:48 pm Post subject: Re: Chat server: referencing CERTAIN clients (connections) i |
|
|
now, I know why did not understand .. without that link is dificult
One Instant Messenger.
| Quote: | From explain more only making one, and not taste of this idea
|
I give up. and I dont like of component that are not of the standard.
good luck! I wait that somebody has time for helping you |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|