hi,
i am looking for a sample program for delphi for a server client. I was wanting to use sockets and i am using pascal. if any one know of any good resource site or has some same code.

I tired the following example

but when i compile t said client socket doesnt have corresponding component???


thanks for looking

Dani AI

Generated

reported a compile error about a missing client socket component after opening an old project; that usually means the form (.dfm) references TClientSocket/TServerSocket but the IDE does not have the socket design package installed. The classic fix is to install the sockets design package (dclsockets*.bpl) so the Internet palette components are registered. Embarcadero also publishes a simple Chat Room example that shows the TServerSocket/TClientSocket events and basic send/receive behavior. (docwiki.embarcadero.com)

For a more modern and robust route, convert the project to Indy (TIdTCPServer / TIdTCPClient). Indy servers use an OnExecute handler per client connection; the handler reads/writes via the context IOHandler. This directly answers ’s question about where to attach read/write logic: use the server’s OnExecute and AContext.Connection.IOHandler methods. Example (minimal):

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
  s: string;
begin
  s := AContext.Connection.IOHandler.ReadLn;
  // parse/process s (do not touch VCL from here)
  AContext.Connection.IOHandler.WriteLn('ACK');
end;

OnExecute runs in a worker thread, so avoid direct VCL calls (use TThread.Queue/Synchronize) and use IOHandler timeouts/checks to avoid blocking forever. (jachguate.github.io)

If a lightweight, no-design-time-install library is preferred (useful for Turbo/older Delphi or console/service apps), Synapse is a solid units-only alternative that can be dropped into a project path and used immediately. For archival/reference, rebuilding the simple chat example with either the installed ScktComp package, Indy, or Synapse is the quickest way to get a working server/client pair. (ararat.cz)

Recommended Answers

All 15 Replies

Member Avatar for Member #82008

I was wanting to use sockets and i am using pascal. if any one know of any good resource site or has some same code.

I have a sample, but I build than with Delphi7 compiler, using TServerSocket and TClientSocket from Internet pallete.

It shows how to:
- save the connected client in order to interchange data;
- send message (text) from client to server and vice-verse;
- send formated command to server to be processed;
- monitore client and server disconnection (server ou client Stop to listen);

Take a look to attachment. If it interest You, let me know because the comments is all in portuguese.

First, start the SocketServer.exe program and click Start Server button. At last, start how many clients (SocketClient.exe program) You want to test. Type the server name to respective edit control (if all prograns in the same machine, You must type LocalHost) and click Start Client.

Bye

the file is corrupt or invalid
,UF

Member Avatar for Member #82008

the file is corrupt or invalid
,UF

I download it with no problem...

So, try download than from my shared resources on 4Shared. Looking for Programacao folder and expand it. There is a folder named Socket and You will see two samples zipped in there.

Bye

This does soemthing close from what I'm looking for. As I guess it is using Indy, I assume it is multithread.
My problem is how to attach the read write handler to the ServerSockeet? I can launch the sever, I can connect a client, but I do not know how to adress the correct handler to read any received message...

Have you checked the examples that come with Indy - and delphi itself?

I'm working with Turbo Delphi and event if Indy seems to be in I don't think I have any example of code. If you can indicate me some of these and where I can reach them It would be great!
Thanks.

You should have the examples, however, you could download them from the indys website as per the readme in the indy directory under your demos.

For server and client socket raw from delphi, there are a number of examples on code central. And in fact theres a tutorial on there for those 2 components.

The site I have in the file leads to a not available page. And on the Indy site I do not see where to download anything!

a open source project maybe what you need!

any luck with finding a program?

Thank you all of you'll for this gr8 information i had also suffered frm this information....

Hi Micheus, i'm very interested of you program server and client socket. Could you sent to me the sources please.!? I am always on hand to listen to you. Thks . my e-mail: andrianome12@gmail.com

Nice try but this thread nine years old. Maybe you should just do your own homework?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.