Jump to content
toufik

NetCom7 clients chat implementation

Recommended Posts

hello,I'm nob , and i did tried today NetCom7 and i would like to say
what an amazing project very fast , believe me i know because we have very low connection speed where i live ,
any way ,

i would like to ask you if any one can give us more demos or example about for example chat communication between two selected clients

lets say client one , select client two to chat with , how do you implement that .
thank you all and have a Delphi day

link:
https://github.com/DelphiBuilder/NetCom7

Share this post


Link to post

Why it always turns me off when I read something advertising itself as the best, the fastest, the smallest or the ultimate...? 😐

Share this post


Link to post

@aehimself
i don't know the guy who made that , and i'm not here for any advertising 
by the way maybe he deserve an  advertisement ^^ 

Share this post


Link to post

I know, it was only my very personal opinion and yes, I can be wrong. I guess - unless a component is really badly written - I doubt that it can cause slowdowns (there can be specific high-end cases where the design can cause a bottleneck but that's an other story).

 

Back to your question. Usually there's not much to set a TCP connection up. You need a server (listener) component and a client (which is connecting to the server) component. Set the port number to the same, set the server and the client to active and it should work.

Sending data is a completely different topic. Are you using text-based or binary communication? For text, most components have a .SendText method which will accept a string parameter. For binary - I don't think we want to go there just yet.

Now look for events of said components. There should be something like... onReceiveBuf, onReceiveText, onDataAvailable... something like this - you have to handle those. And within that event handler, you have to read the data out of the socket with... socket.Read socket.ReceiveText, socket.receivebuf or something.

Unfortunately that's all I can say, as I never used this component.

 

Did you look at the Demo folder? There seems to be a chat application - just the one what you are looking for.

  • Thanks 1

Share this post


Link to post

@aehimself
Thank a lot for  reply , and yes there is demo folder , but it s missing what  i'm looking for ,
the demos contain chat application ,that all client can see the text message that one client sent 
'see the picture'
and i want like i said before 
client 1 select client 2 to text with privately , i hope you understand the idea 

 

Untitled.png

Edited by toufik

Share this post


Link to post

Ahaaaa, makes sense. This is how IRC worked.

To have a "private" chat, you have 2 options:

1, Look in the source of the OnReceive event of the server. Instead of sending the received message to everyone, if the message contains a special flag, send it to one recipient only. For example, if you start your message with "@IP" then it will look for all connected clients, and where the IP address matches - send the message only there

2, A more secure way is if you initiate a DCC-like (again, IRC did it this way) channel. If the message starts with @IP DCC, the server will send your IP address to @IP. Then, on your client, you open up a server socket and wait for a connection from @IP.

 

Long story short, wither your message will travel around the network twice (thus, more vulnerable) or you have to establish a client-server connection directly between the TWO CLIENTS:

 

image.thumb.png.4731987ec97add148fb6a90d5feb47f7.png

  • Like 1

Share this post


Link to post

Thank you very much for help , i will try to accomplish what you suggested ,again thank you ^^ 
 

Share this post


Link to post
On 8/30/2020 at 8:59 PM, aehimself said:

Why it always turns me off when I read something advertising itself as the best, the fastest, the smallest or the ultimate...? 😐

Not if it's about a Delphi/Pascal library component. On the opposite, I feel exciting when I hear a Delphi/Pascal library is advertised as fast, lightweight, high performance, or something like that, maybe the Delphi community/market is very small and we really need quality libraries and components.


And my past experience shown that when a Delphi library/component is advertised as fast, it's usually fast, at least it proves the author really has a passion, or really tried to make it fast.

Share this post


Link to post
3 hours ago, Edwin Yip said:

maybe the Delphi community/market is very small and we really need quality libraries and components.

That is true; more that true actually. I remember back in the 2000s browsing Torry's Delphi Pages for components and I was not really able to choose from the incredible amount. Oh, and I remember how many were free!

3 hours ago, Edwin Yip said:

And my past experience shown that when a Delphi library/component is advertised as fast, it's usually fast, at least it proves the author really has a passion, or really tried to make it fast.

Don't get me wrong, I'm not going to judge anything I have no experience with. Been there, done that, burnt myself, never again. I just gave an unpleasant grin to the "marketing".

Share this post


Link to post
7 hours ago, aehimself said:

That is true; more that true actually. I remember back in the 2000s browsing Torry's Delphi Pages for components and I was not really able to choose from the incredible amount. Oh, and I remember how many were free!

Don't get me wrong, I'm not going to judge anything I have no experience with. Been there, done that, burnt myself, never again. I just gave an unpleasant grin to the "marketing".

I see, that's my feeling too when facing general marketing. I guess only the marketing/advertising of open source Delphi libraries will make me happen. That's a very rare exception.

 

BTW, what do you mean by "burnt myself" in this context?

Share this post


Link to post
16 hours ago, Edwin Yip said:

Not if it's about a Delphi/Pascal library component. On the opposite, I feel exciting when I hear a Delphi/Pascal library is advertised as fast, lightweight, high performance, or something like that, maybe the Delphi community/market is very small and we really need quality libraries and components.

Usually if some lib asserts itself to be fast, it must at least include benchmark results and ideally the reproducible tests. Otherwise this label is not more trustful and reliable than "the best in the world" assertion.

Share this post


Link to post
44 minutes ago, Fr0sT.Brutal said:

Usually if some lib asserts itself to be fast, it must at least include benchmark results and ideally the reproducible tests. Otherwise this label is not more trustful and reliable than "the best in the world" assertion.

 

Quote

 

This set of components promises unrivalled speed and that is not just in words:

A simple timing test with the NetComVSIndy demo gives the following results:

  • Testing Indy... Time taken: 32468 msec
  • Testing NetCom... Time taken: 25109 msec

 

  •  

Share this post


Link to post
Guest
On 8/30/2020 at 2:13 PM, toufik said:

i would like to ask you if any one can give us more demos or example about for example chat communication between two selected clients

How about explaining how to do it and you can try, this will help you more than a simple demo, so i will list and explain how to do it and you must try to do it on your own, this is not i don't want to help and waste my time, as i am wasting time in writing this post more than the time needed to write that demo you need, the thing is after you do it your self you will not need another help in this matter or any similar for ever.

 

( i looked at the server/client chat demo in github and will use it as reference)

So lets begin

You need your own protocol, sound fancy ?!, yes and no, it is simple as you need to implement some sort of messaging mechanism, like when client is sending text it must be packet telling the server it is text and the server will send it to one or many so they will receive text from X.

So the minimum design modification you need as follow

1) When client connect event is triggered the client should send his name to the server, server will maintain a list of the tcp connections and their client names/ids.

2) When connection lost (or may be later you want to add specific log out message to see the user lost connection or logged out ), the server should notify all users that user is gone ( or had lost connection).

3) When this packet of ( lets call it) login message, server will will answer as accept to him and send to every one that X ( toufik1) joined the chat, here you can answer him with his id ( some integer will do) and send to everyone else his name and his id as joined, this is simple as execute command to him and loop to everyone

4) after login and receive an id server will also send him a list of all available users with their id's, or only names, i want to mention that you can use their names instead of id's

5) practically you are done, when client will send text it has a field to tell the server this text is for all or for one, server will send it accordingly.

 

So in short your protocol need to have those messages

1) new user joined the chat

2) current online users

3) user left the chat

4) chat text message, this is two-in-one, is it public to all or to one user, and it can be two message

  A) public text

  B) private text

   

Now judging by how that component have this ClientHandleCommand and ServerHandleCommand implemented, which already does have "aCmd: Integer" all those protocol messages mentioned above is simple as adding aCmd value for them, and those handlers should have case..of , i think yo got the idea now.

 

So try to do it, i am sure you will feel way better after doing it yourself, will learn many things that you will never forget, if you try and still can't do it then come back and ask what is the problem you are facing, you will get the help here.

Share this post


Link to post
17 hours ago, Edwin Yip said:

BTW, what do you mean by "burnt myself" in this context?

It was outside of the IT area, a real-world thing. Unfortunately I can not remember (happened a long-long time ago) but for example:

- I have a personal problem with John Doe, and he writes an application

- Since I don't like him, I start to talk sh*t and discourage people from using his product

- Everyone is still using it. Then, it turns out it has a bridge to some inconvenience I faced for years

- I start to use it because of that minor thing and it turns out the application is pretty good

- Now, try to explain to everyone you discouraged why exactly you are now a user too

- ???

- Profit

 

Fortunately, the only thing I achieved is my own humiliation, no legal stuff. It was still a remarkable experience.

  • Haha 2

Share this post


Link to post

i did get this form the programmer  who has written NetCom7 :
you can pass that information to the server by packing it in the aData parameter (for example, you could pack the other client's info and the data with a TStringList.CommaText and pass that as aData). Now, the server will have to unpack the aData, again using TStringList.CommaText,
and i'm trying it right now 

Share this post


Link to post

Hi,

I'm having a problem installing component NetCom7.dpk on Delphi XE5

 

Error on following line : if not ReadableAnySocket([Line.Handle], aTimeout) then

 

[dcc32 Error] ncSockets.pas(690): E2010 Incompatible types: 'TSocketHandleArray' and 'Set'

 

 

From the unit ncSockets.pas and below is the function:

 

function TncCustomTCPClient.Receive(aTimeout: Cardinal): TBytes;
var
BufRead: Integer;
begin
if UseReaderThread then
raise ECannotReceiveIfUseReaderThread.Create(ECannotReceiveIfUseReaderThreadStr);

Active := True;

if not ReadableAnySocket([Line.Handle], aTimeout) then
begin
SetLength(Result, 0);
Exit;
end;

BufRead := TncLineInternal(Line).RecvBuffer(ReadBuf[0], Length(ReadBuf));
Result := Copy(ReadBuf, 0, BufRead)
end;

ncSockets.pas

ncLines.pas

Share this post


Link to post

I need a reliable tcp server and client , particularly since there is no support/docs for INDY at this time.

I tired to install in Rad Studio 11 but get an error after installing the .bpl and using a server component in a form.

[dcc32 Fatal Error] NetComRegister.pas(16): F2613 Unit 'ToolsAPI' not found.

 

I was trying to use w32 for now before also doing on Android. 

Are there install instructions since that is likely where something went wrong , not sure.

 

Edited by clarke

Share this post


Link to post

@clarke Since the D7 era I was using Delphi's own TClientSocket - TServerSocket. Had some quirks but it worked perfectly.

Due to a bug in my receiver code (which originally I thought is in the component) I migrated to ICS about a year ago. A bit more complicated, but works perfectly as well.

 

Depending on your needs you can check these out. ICS works fine on D11 (I'm unsure if TClientSocket - TServerSocket is still shipped, though), both has decent documentation.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×