Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 14-06-2010
jlsc jlsc is offline
Miembro
 
Registrado: may 2007
Posts: 38
Poder: 0
jlsc Va por buen camino
Socket Error

Hola compañero,

Este es el codigo:

Código Delphi [-]
unit UMensaCliente;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs,
  StdCtrls, ScktComp, Mask, DBCtrls, ExtCtrls, jpeg, IdBaseComponent, IdComponent, IdTCPConnection,
  IdSimpleServer, IdTCPServer, IdMappedPortTCP, IdTCPClient, Sockets, Menus, Gauges, Buttons,
  Grids, DirOutln, ComCtrls, Spin, ShellApi, Winsock, IdIPWatch, ImgList;
type
  TThePhoneHouseForm = class(TForm)
    ClientSocket1: TClientSocket;
    IdIPWatch1: TIdIPWatch;
    Image3: TImage;
    mMensaje: TMemo;
    StatusBar1: TStatusBar;
    Panel1: TPanel;
    MainMenu1: TMainMenu;
    Menu1: TMenuItem;
    Cerrar1: TMenuItem;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure ClientSocket1Connect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure FormDestroy(Sender: TObject);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocket1Disconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure Timer1Timer(Sender: TObject);
    procedure Cerrar1Click(Sender: TObject);
  private
    { Private declarations }
    IconData : TNotifyIconData;
    procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION;
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
    procedure Espabila(var Msg : TMessage); message WM_USER+1 ;
  public
    { Public declarations }
  end;
var
  ThePhoneHouseForm: TThePhoneHouseForm;
  ControlaError:Integer;
  
implementation
uses Acerca;
{$R *.dfm}
function GetUserName : string;
var
  tamanoBuffer: Cardinal;
  bufferUsuario: array[0..MAX_PATH] of Char;
begin
  tamanoBuffer := SizeOf(bufferUsuario);
  Windows.GetUserName(bufferUsuario, tamanoBuffer);
  Result := bufferUsuario;
end;
procedure TThePhoneHouseForm.WMQueryEndSession(var Msg: TWMQueryEndSession);
begin
ClientSocket1.Active:=false;
Application.Terminate;
ExitWindowsEx(EWX_FORCE,0);
end;
function IPAddrToName(IPAddr: string): string;
var
  SockAddrIn: TSockAddrIn;
  HostEnt: PHostEnt;
  WSAData: TWSAData;
begin
  WSAStartup($101, WSAData);
  SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
  HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
  if HostEnt <> nil then
    Result := StrPas(Hostent^.h_name)
  else
    Result := '';
end;
procedure TThePhoneHouseForm.FormCreate(Sender: TObject);
begin
ClientSocket1.Port:= 9923;
ClientSocket1.Host:='10.34.18.125';
ClientSocket1.Active:=true;
ControlaError:=1;
end;
procedure TThePhoneHouseForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 ClientSocket1.Active:=False;
end;
procedure TThePhoneHouseForm.WMSysCommand(var Msg: TWMSysCommand);
 begin
   if (Msg.CmdType = SC_Close) then begin
     with IconData do
     begin
       cbSize := sizeof(IconData);
       Wnd := Handle;
       uID := 100;
       uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
       uCallbackMessage := WM_USER + 1;
       {Usamos de icono el mismo de la aplicacion}
       {We use the same icon as the application}
       hIcon := Application.Icon.Handle;
       {Como Hint del icono, el nombre de la aplicacion}
       {The name of te app for the hint of the icon}
       StrPCopy(szTip, Application.Title);
     end;
     {Ponemos el icono al lado del reloj}
     {Place the icon next to the clock}
     Shell_NotifyIcon(NIM_ADD, @IconData);
     {Ocultamos la Form...}
     {Hide the form...}
     Hide;
   end else DefaultHandler(Msg);
 end;
procedure TThePhoneHouseForm.Espabila(var Msg : TMessage);
 {Aqui se recibe la pulsacion sobre el icono}
 {Here we recieve the click on the icon}
 var
   p : TPoint;
 begin
   if Msg.lParam = WM_LBUTTONDOWN then begin
   ThePhoneHouseForm.Show;
   ShowWindow(Application.Handle, SW_HIDE);
   {Y nos cargamos el icono de la system tray}
   {Destroy the systray icon}
   Shell_NotifyIcon(NIM_DELETE, @IconData);
   IconData.Wnd:=0;
   end;
 end;
procedure TThePhoneHouseForm.Button1Click(Sender: TObject);
begin
if ClientSocket1.Active=true then
ClientSocket1.Socket.SendText(mMensaje.text);
end;
procedure TThePhoneHouseForm.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
var
bTemp:TBitmap;
begin
ClientSocket1.Socket.SendText(ClientSocket1.Socket.LocalHost+','+ClientSocket1.Socket.LocalAddress+'  ,'+GetUserName+','+''+','+'Conectado'+',');
Statusbar1.Panels[0].Text :='Conectado';
Statusbar1.Panels[1].Text :='';
Timer1.Enabled:=false;
ControlaError:=1;
end;
procedure TThePhoneHouseForm.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
ClientSocket1.Active:=false;
Statusbar1.Panels[1].Text :='Desconectado: Imposible conectar a ' + ClientSocket1.Host + '     ';
Statusbar1.Panels[0].Text :='';
ControlaError:=0;
ErrorCode := 0;
Timer1.Enabled:=true;
end;

procedure TThePhoneHouseForm.FormDestroy(Sender: TObject);
begin
 ClientSocket1.Active:=False;
end;
procedure TThePhoneHouseForm.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
begin
ThePhoneHouseForm.Show;
ShowWindow(Application.Handle, SW_HIDE);
   {Y nos cargamos el icono de la system tray}
   {Destroy the systray icon}
Shell_NotifyIcon(NIM_DELETE, @IconData);
IconData.Wnd:=0;
mMensaje.Clear;
mMensaje.Lines.Add(ClientSocket1.Socket.ReceiveText+' '+ TimeToStr(now));
end;
procedure TThePhoneHouseForm.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
if ((ClientSocket1.Active=false) and (ControlaError<>0 ))then
ClientSocket1.Socket.SendText(ClientSocket1.Socket.LocalHost+','+ClientSocket1.Socket.LocalAddress+'  ,'+GetUserName+','+''+'*'+'Desconectado'+',');
ClientSocket1.Active:=false;
Statusbar1.Panels[1].Text :='Desconectado: Imposible conectar a ' + ClientSocket1.Host + '     ';
Statusbar1.Panels[0].Text :='';
Timer1.Enabled:=true;
ControlaError:=1;
end;
procedure TThePhoneHouseForm.Timer1Timer(Sender: TObject);
begin
if (ClientSocket1.Active=false) then
  ClientSocket1.Active:=True
end;
procedure TThePhoneHouseForm.Cerrar1Click(Sender: TObject);
begin
Acercade.Show;
Acercade.Timer1.Enabled:=true;
end;
end.

Última edición por rgstuamigo fecha: 14-06-2010 a las 20:31:39. Razón: Estética en el código
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Uso de sockets vejerf Internet 3 15-11-2007 21:44:16
Sockets Caral Varios 4 29-08-2006 22:29:39
ADO y Sockets krilea Conexión con bases de datos 3 21-04-2005 22:38:55
Sockets con DB Slash Internet 1 08-07-2004 19:58:18
sockets the darkness Internet 7 28-04-2004 18:56:13


La franja horaria es GMT +2. Ahora son las 22:19:06.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi