Master Games
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Procurar
 
 

Resultados por:
 


Rechercher Pesquisa avançada

Cbox
Entrar

Esqueci-me da senha

Essenciais
Últimos assuntos
» MuServer 1.06A + Imperions + DBZ + New Itens
Chat Em Delphi! - Client + Servidor EmptyQua Dez 25, 2013 12:37 am por Sirius

» Recrutamento King Cheats
Chat Em Delphi! - Client + Servidor EmptyDom Abr 08, 2012 9:15 pm por gealves

» Parceiria????
Chat Em Delphi! - Client + Servidor EmptyQua Fev 08, 2012 7:29 pm por Pocahontas

» Novo botão de download da MasterGames
Chat Em Delphi! - Client + Servidor EmptyQua Fev 08, 2012 7:28 pm por Pocahontas

» Hello .
Chat Em Delphi! - Client + Servidor EmptyQua Fev 08, 2012 7:28 pm por Pocahontas

» Sobre A Nova Era DDTank...
Chat Em Delphi! - Client + Servidor EmptyTer Jan 24, 2012 11:06 pm por Snow

» MuNect|Iaugurando Dia 20/jul/11 as 8:00hrs|Super Eventos|Não perca.
Chat Em Delphi! - Client + Servidor EmptyTer Jul 19, 2011 9:25 pm por felipebme

» Angel Trainer Hack
Chat Em Delphi! - Client + Servidor EmptyQua Fev 23, 2011 7:52 pm por TEUSO97

» [Tradução] Pro Evolution Soccer 2011
Chat Em Delphi! - Client + Servidor EmptyQua Nov 03, 2010 8:19 pm por PMD PKMN


Chat Em Delphi! - Client + Servidor

Ir para baixo

Chat Em Delphi! - Client + Servidor Empty Chat Em Delphi! - Client + Servidor

Mensagem por Snow Sex Ago 20, 2010 5:45 pm

Depois de muita falta de sucesso no chat em Visual Basic, cá estou com um chat em Delphi.


CLIENTE:

1 - Adicione 2 Memos, 3 Edits e um Client Socket, dê os nomes e posicione de acordo com a imagem abaixo:

Chat Em Delphi! - Client + Servidor Cliente

1.5 - Mude a Port do Client Socket para um valor que não esteja sendo usado ( eu uso 7171 ).

2 - Códigos:


2.1 - Evento KeyDown do edit Text:

begin
if Key = VK_Return then
begin
if Text.Text <> '' then
begin
ClientSocket1.Socket.SendText(Text.Text + '::::' + Name.Text);
Text.Text := '';
end;
end;
end;

2.2 - Evento OnClick do botão Connect:

begin
if ClientSocket1.Active then
begin
ClientSocket1.Active := False;
Connect.Caption := 'Conectar';
end
else begin
ClientSocket1.Host := Host.Text;
ClientSocket1.Active := True;
end;
end;

2.3 - Evento Connect do ClientSocket1:

begin

Status.Lines.Add('Cliente ::> Conectado a: ' + ClientSocket1.Host);
Connect.Caption := 'Desconectar';

Name.Enabled := False;
ClientSocket1.Socket.SendText('NICK::::' + Name.Text);

end;

2.4 - Evento Disconnect do ClientSocket1:

begin
Status.Lines.Add('Cliente ::> Desconectado ');
Connect.Caption := 'Conectar';
Name.Enabled := True;
end;

2.5 - Evento Error do ClientSocket1:

begin
Status.Lines.Add('Cliente ::> ERRO ao tentar conectar a: ' + ClientSocket1.Host);
end;

2.6 - Evento Read do Client Socket1:

begin
Messages.Lines.Add(Socket.ReceiveText);
end;

2.7 - Evento OnClick do botão Send:

begin
if Text.Text <> '' then
begin
ClientSocket1.Socket.SendText(Text.Text + '::::' + Name.Text);
Text.Text := '';
end;
end;

SERVIDOR:

1 - Adicione 2 Memos, 1 Edits, um Server Socket e um Client Socket, dê os nomes e posicione de acordo com a imagem abaixo:

Chat Em Delphi! - Client + Servidor Servidorn

1.5.1 - Mude a Port do Client Socket para um valor que não esteja sendo usado ( eu uso 7171 ).
1.5.2 - Mude a Port do Server Socket para o mesmo valor do ClientSocket ( eu uso 7171 ).

2 - Códigos:

2.1 - Evento KeyDown do edit Text:

begin
if Key = VK_Return then
begin
if Text.Text <> '' then
begin
ClientSocket1.Socket.SendText(Text.Text + '::::' + 'Admin');
Text.Text := '';
end;
end;
end;

2.2 - Evento Connect do ClientSocket1:

begin
Status.Lines.Add('Cliente ::> Conectado a: ' + ClientSocket1.Host);

ClientSocket1.Socket.SendText('NICK::::' + 'Admin');
end;

2.3 - Evento Disconnect do ClientSocket1:

begin
Status.Lines.Add('Cliente ::> Desconectado ');

end;

2.4 - Evento Error do ClientSocket1:

begin
Status.Lines.Add('Cliente ::> ERRO ao tentar conectar a: ' + ClientSocket1.Host);
end;

2.5 - Evento Read do ClientSocket1:ClientSocket1

begin
Messages.Lines.Add(Socket.ReceiveText);
end;

2.6 - Evento onClick do botão Start:

begin
if ServerSocket1.Active = True then
begin
ServerSocket1.Active := False;

Status.Lines.Add('Servidor ::> Servidor Desligado!');
Start.Caption := 'Iniciar Servidor';
ClientSocket1.Active := False;
end
else begin
ServerSocket1.Active := True;
Start.Caption := 'Parar Servidor';
ClientSocket1.Host := '127.0.0.1';
ClientSocket1.Active := True;
end;
end;

2.7 - Evento Listen do ServerSocket1:

begin
Status.Lines.Add('Servidor ::> Servidor Ligado!');
end;

2.8 - Evento ClientConnect do ServerSocket1:

begin
Status.Lines.Add('Servidor ::> Usuário Conectado => '+ Socket.RemoteAddress);
end;

2.9 - Evento ClientDisconnect do ServerSocket1:

begin
Status.Lines.Add('Servidor ::> Usuário Desconectado => '+ Socket.RemoteAddress);
end;

3 - Evento ClientRead do ServerSocket1:

var texto: array[0..1] of string;
temptexto: string;
Index: integer;
begin

temptexto := Socket.ReceiveText;
texto[0] := Copy(temptexto, 1,Pos('::::', temptexto) -1);
texto[1] := Copy(temptexto, Pos('::::', temptexto) + Length('::::'),Length(temptexto));
if texto[0] = 'NICK' then {Verifica se a mensagem eh de entrada}
begin

WITH ServerSocket1.Socket DO BEGIN {Se a msg for de entrada avisa a todos os clientes quem entrou }
FOR Index := 0 TO ActiveConnections-1 DO BEGIN
Connections[Index].SendText(texto[1] + ' entrou na sala: ');
END;
END;
end

else

begin
WITH ServerSocket1.Socket DO BEGIN {Se nao for de entrada, então eh msg normal, no caso passa para todos a msg}
FOR Index := 0 TO ActiveConnections-1 DO BEGIN
Connections[Index].SendText('(' + texto[1] + ') escreveu: ' + texto[0]);
END;
END;

Status.Lines.Add('Servidor ::> ' + texto[1] + ' (' + Socket.RemoteAddress + ') escreveu: '+ texto[0]);
end;

end;

3.1 - Evento onClick do botão Send:

begin
if Text.Text <> '' then
begin
ClientSocket1.Socket.SendText(Text.Text + '::::' + 'Admin');
Text.Text := '';
end;
end;

IMPORTANTE:


QuoteDesativar o firewall ?
Não, só adicionar a porta utilizada em exceções.
Snow
Snow
Admin
Admin

Diretor

Respeito as regras : 100

Level :
Chat Em Delphi! - Client + Servidor Left_bar_bleue100 / 100100 / 100Chat Em Delphi! - Client + Servidor Right_bar_bleue


Infrações :
Chat Em Delphi! - Client + Servidor Left_bar_bleue0 / 300 / 30Chat Em Delphi! - Client + Servidor Right_bar_bleue

Posts Posts : 259
Gold Gold : 1000629
Reputação Reputação : 5
Idade Idade : 29
Conhecimento : Programação

https://kingcheats.forumbrasil.net

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos