Jump to content
c0smyn

Client-Server delphi [tutorial]

Recommended Posts

Posted

Client

1. Adaugam pe form un tcpclient, 3edit , 2buttons

2. La edit1 punem la text "Adresa IP"

3. La edit2 punem la text "Port"

4. La edit3 la text punem "Mesaj"

5. La button1, punem la caption "Conectare"

6. La button2, punem la caption "Trimite"

7. 2click pe button1 si punem acest cod


tcpclient1.remotehost := edit1.text; [color=lime]//setam adresa ip[/color]
tcpclient1.remoteport := edit2.text; [color=lime]//setam portul[/color]
tcpclient1.connect; [color=lime]//conectare[/color]

8. 2click pe tcpclient si punem acest cod


showmessage('Esti conectat pe '+tcpclient1.remotehost+' : '+tcpclient1.remoteport); [color=lime]// vei fi avertizat cand te`ai conectat, cu acest mesaj[/color]
tcpclient1.sendln('Conectat');

9. 1click pe tcpclient, ne ducem la events si la OnDisconnect punem acest cod


showmessage('Deconectat'); [color=lime]// vei fi avertizat cand te`ai deconectat[/color]

10. 2click pe button2 si punem acest cod


if edit3.gettextlen > 0 then tcpclient1.sendln(edit3.text) else showmessage('Scrie un mesaj');

Server

1. Adaugam pe form un tcpserver

2. Adaugam pe server un memo

3. 2click pe tcpserver, stergem cuvantul "begin" si punem acest cod


var
s: string;
begin
s := tcpserver1.receiveln;
while s <> '' then begin
s := tcpserver1.receiveln;
memo1.lines.add(s); [color=lime]// adaugam in memo textul primit de la client[/color]
end;
end;

4. 1click pe tcpserver si din objectinspector modificam urmatoarele:


Active: true
Localport: 2323

icon6.gif

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...