亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? twschat1.pas

?? 包含常用Internet協(xié)議TCP,UDP、HTTP、FTP、Telnet等
?? PAS
字號:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Author:       Fran鏾is PIETTE
Description:  TWSChat shows how to use TWSocket to build a chat program
Creation:     November 26, 1997
Version:      1.03
EMail:        francois.piette@pophost.eunet.be   
              francois.piette@rtfm.be             http://www.rtfm.be/fpiette
Support:      Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1997, 1998 by Fran鏾is PIETTE
              Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
              <francois.piette@pophost.eunet.be>

              This software is provided 'as-is', without any express or
              implied warranty.  In no event will the author be held liable
              for any  damages arising from the use of this software.

              Permission is granted to anyone to use this software for any
              purpose, including commercial applications, and to alter it
              and redistribute it freely, subject to the following
              restrictions:

              1. The origin of this software must not be misrepresented,
                 you must not claim that you wrote the original software.
                 If you use this software in a product, an acknowledgment
                 in the product documentation would be appreciated but is
                 not required.

              2. Altered source versions must be plainly marked as such, and
                 must not be misrepresented as being the original software.

              3. This notice may not be removed or altered from any source
                 distribution.

Updates:
Jan 04, 1998  V1.01 Corrected a bug in the CliWSocketDataAvailable which did'nt
              append data to the receive buffer.
Jan 10, 1998  V1.02 Corrected yet another bug in CliWSocketDataAvailable which
              did'nt take into account that variable I is zero based.
Mar 15, 1998  V1.03 Yet another bug in OnDataAvailable event.

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit twschat1;

interface

uses
  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, WinSock, WSocket;

const
  TWSChatVersion = 103;
  ChatPort       = '2200';             { Any port would do the job... }

type
  TTWSChatForm = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    DisplayMemo: TMemo;
    SrvWSocket: TWSocket;
    ServerEdit: TEdit;
    Label1: TLabel;
    ConnectButton: TButton;
    CliWSocket: TWSocket;
    DisconnectButton: TButton;
    MessageEdit: TEdit;
    SendButton: TButton;
    TmpWSocket: TWSocket;
    RunningRadioButton: TRadioButton;
    StoppedRadioButton: TRadioButton;
    procedure FormShow(Sender: TObject);
    procedure ConnectButtonClick(Sender: TObject);
    procedure CliWSocketDnsLookupDone(Sender: TObject; Error: Word);
    procedure CliWSocketSessionConnected(Sender: TObject; Error: Word);
    procedure DisconnectButtonClick(Sender: TObject);
    procedure SrvWSocketSessionAvailable(Sender: TObject; Error: Word);
    procedure CliWSocketSessionClosed(Sender: TObject; Error: Word);
    procedure CliWSocketDataAvailable(Sender: TObject; Error: Word);
    procedure SendButtonClick(Sender: TObject);
    procedure StoppedRadioButtonClick(Sender: TObject);
    procedure RunningRadioButtonClick(Sender: TObject);
  private
    { D閏larations priv閑s }
    Initialized : Boolean;
    RcvBuf : array [0..1023] of char;
    RcvLen : integer;
    procedure StartServer;
  public
    { D閏larations publiques }
  end;

var
  TWSChatForm: TTWSChatForm;

implementation

{$R *.DFM}


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTWSChatForm.StartServer;
begin
    { Try to be a server }
    SrvWSocket.Port  := ChatPort;
    SrvWSocket.Proto := 'tcp';
    SrvWSocket.Addr  := '0.0.0.0';
    try
        SrvWSocket.Listen;
        RunningRadioButton.Checked := TRUE;
        StoppedRadioButton.Checked := FALSE;
    except
        on E:ESocketException do begin
            { The socket is probably already in use }
            RunningRadioButton.Checked := FALSE;
            StoppedRadioButton.Checked := TRUE;
            if Copy(E.Message, 1, 11) = 'Error 10048' then
                DisplayMemo.Lines.Add('TWSChat already running as server')
            else
                raise;
        end
        else
            raise;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTWSChatForm.FormShow(Sender: TObject);
begin
    if not Initialized then begin
        Initialized := TRUE;
        StartServer;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ The user has clicked on the 'connect' button. We will not connect here,   }
{ but start the DNSLookup. We will receive a event when it is complete.     }
{ The connection will be made at that later time.                           }
procedure TTWSChatForm.ConnectButtonClick(Sender: TObject);
begin
    ConnectButton.Enabled    := FALSE;
    DisconnectButton.Enabled := TRUE;
    CliWSocket.DnsLookup(ServerEdit.Text);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is triggered when the DNS lookup process is finished   }
{ successfully or not. If DNS lookud failed, display a message.             }
{ If DNS lookup successfull, ask TWSocket to connect the server.            }
procedure TTWSChatForm.CliWSocketDnsLookupDone(Sender: TObject; Error: Word);
begin
    if Error <> 0 then begin
        { DNS Lookup has failed }
        DisplayMemo.Lines.Add('Server name unknown');
        ConnectButton.Enabled    := TRUE;
        DisconnectButton.Enabled := FALSE;
        Exit;
    end;

    { DNS lookup successfull. Try to see if we are the server and we are }
    { trying to connect to ourself. Check loopback address, should also  }
    { check the local IP address (returned by LocalIPList)...            }
    if (SrvWSocket.State = wsListening) and
       (CliWSocket.DnsResult = '127.0.0.1') then begin
        DisplayMemo.Lines.Add('Your are trying to connect to yourself !');
        ConnectButton.Enabled    := TRUE;
        DisconnectButton.Enabled := FALSE;
        Exit;
    end;

    { Transfert the IP address from DNSLookup to the TWSocket for connection }
    { We could use the hostname for the Addr property, TWSocket will do the  }
    { DNS lookup for us, but it will block, maybe for a long time if DNS if  }
    { down.                                                                  }
    CliWSocket.Addr  := CliWSocket.DnsResult;
    CliWSocket.Port  := ChatPort;
    CliWSocket.Proto := 'tcp';

    { The connect method is asynchronous. You get the control back quickly }
    { The OnSessionConnected event will be eventually generated when the   }
    { connection is established.                                           }
    CliWSocket.Connect;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is triggered when the connection is established with   }
{ the server. Enable the send button and the message edit box.              }
procedure TTWSChatForm.CliWSocketSessionConnected(Sender: TObject; Error: Word);
begin
    if Error = WSAECONNREFUSED then
        DisplayMemo.Lines.Add('No server available')
    else if Error <> 0 then
        DisplayMemo.Lines.Add('Can''t connect, error #' + IntToStr(Error))
    else begin
        DisplayMemo.Lines.Add('Connected');
        SendButton.Enabled  := TRUE;
        MessageEdit.Enabled := TRUE;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event is triggered when the client connection is closed, either      }
{ by the client himself or by the local user pushing the disconnect button  }
procedure TTWSChatForm.CliWSocketSessionClosed(Sender: TObject; Error: Word);
begin
    DisconnectButton.Enabled := FALSE;
    ConnectButton.Enabled    := TRUE;
    if SendButton.Enabled then begin
        SendButton.Enabled   := FALSE;
        MessageEdit.Enabled  := FALSE;
        DisplayMemo.Lines.Add('Disconnected');
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event is triggered when data has been received from the client.      }
{ A little bit of work here because the data can comes fragmented or in big }
{ chunks with several client lines. So we assemble the data received in a   }
{ buffer and check the buffer for complete lines (there can be no complete  }
{ line, exactly one complete line, several complete lines and may be an     }
{ incomplete line at the end.                                               }
procedure TTWSChatForm.CliWSocketDataAvailable(Sender: TObject; Error: Word);
var
    Len : Integer;
    I   : Integer;
begin
    { Receive the data that has arrived, put it after the data already here }
    Len := CliWSocket.Receive(@RcvBuf[RcvLen], SizeOf(RcvBuf) - RcvLen - 1);
    if Len <= 0 then
        Exit;
    { Update our conter }
    RcvLen := RcvLen + Len;
    { Place a null byte at the end of the buffer }
    RcvBuf[RcvLen] := #0;

    { Scan the buffer to process each complete line }
    while TRUE do begin
        { find the terminating line feed }
        I := StrScan(@RcvBuf, #10) - RcvBuf;
        if I < 0 then
            break; { not found, incomplete line, break loop }
        { Replace the line feed by a nul char, truncating the line }
        RcvBuf[I] := #0;
        { Display the truncated line }
        DisplayMemo.Lines.Add('Remote> ' + StrPas(RcvBuf));
        { Restore the line feed }
        RcvBuf[I] := #10;
        { Was it the last line in the buffer ? }
        if I >= (RcvLen - 1) then begin
            RcvLen := 0;
            break;
        end;
        { Not the last line, move the next one in front of buffer }
        Move(RcvBuf[I + 1], RcvBuf, RcvLen - I);
        RcvLen := RcvLen - I - 1;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event is triggered when we - as a server - have received a client    }
{ connection request. We must accept the connection. Two cases: we are      }
{ already busy with another client, or this is the first client connecting. }
procedure TTWSChatForm.SrvWSocketSessionAvailable(Sender: TObject; Error: Word);
begin
    if CliWSocket.State = wsConnected then begin
        { We are already busy with a client. Use the TmpWSocket to send a }
        { busy message to the second client. Display a message to notify  }
        { the user that someone is trying to contact him.                 }
        TmpWSocket.HSocket := SrvWSocket.Accept;
        DisplayMemo.Lines.Add('System> ' + TmpWSocket.GetPeerAddr +
                              ' is trying to call you');
        TmpWSocket.SendStr('Busy ! Try later...' + #13#10);
        TmpWSocket.Close;
        Exit;
    end;

    { This is our first client trying to connect, we accept }
    CliWSocket.HSocket       := SrvWSocket.Accept;
    ConnectButton.Enabled    := FALSE;
    DisconnectButton.Enabled := TRUE;
    SendButton.Enabled       := TRUE;
    MessageEdit.Enabled      := TRUE;
    DisplayMemo.Lines.Add('Connected with ' + CliWSocket.GetPeerAddr);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ The user clicked on the disconnect button.                                }
procedure TTWSChatForm.DisconnectButtonClick(Sender: TObject);
begin
    CliWSocket.Close;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ The user has clicked on the send button. Just send the data in the edit   }
{ box and a CRLF pair to make a complete line.                              }
procedure TTWSChatForm.SendButtonClick(Sender: TObject);
begin
    CliWSocket.SendStr(MessageEdit.Text + #13#10);
    DisplayMemo.Lines.Add(' Local> ' + MessageEdit.Text);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTWSChatForm.StoppedRadioButtonClick(Sender: TObject);
begin
    SrvWSocket.Close;
    RunningRadioButton.Checked := FALSE;
    StoppedRadioButton.Checked := TRUE;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTWSChatForm.RunningRadioButtonClick(Sender: TObject);
begin
    if SrvWSocket.State <> wsListening then
        StartServer;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

end.

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久精品综合| 理论电影国产精品| 精品国产乱码久久| 欧美一区二区三区在线观看| 色婷婷综合五月| 日本乱人伦aⅴ精品| 91视频在线观看免费| 91啪亚洲精品| 欧美日韩在线不卡| 91精品国产日韩91久久久久久| 欧美丰满少妇xxxbbb| 欧美一区二区三区在线| 午夜精品免费在线| 国产精品一区二区久激情瑜伽| 亚洲欧美偷拍三级| 色综合久久天天综合网| 亚洲卡通欧美制服中文| 亚洲影院久久精品| 性感美女久久精品| 麻豆国产一区二区| 国产不卡视频一区二区三区| 99久久99久久久精品齐齐| 欧美亚洲国产bt| 精品欧美一区二区在线观看| 国产三级欧美三级日产三级99| 国产精品美女久久久久高潮| 一区二区欧美国产| 久久99精品国产91久久来源 | 国内国产精品久久| 成人黄色国产精品网站大全在线免费观看| 国产黄人亚洲片| 秋霞电影一区二区| 日本sm残虐另类| 日韩电影在线免费看| 免费精品视频在线| 丁香亚洲综合激情啪啪综合| 欧亚洲嫩模精品一区三区| 91精品国产入口| 国产精品国产三级国产普通话蜜臀| 亚洲国产另类精品专区| 国产一区福利在线| 欧美综合天天夜夜久久| 久久久久久电影| 亚洲一区av在线| 成人精品鲁一区一区二区| 91精品欧美综合在线观看最新| 欧美激情一区二区| 亚洲精品国产一区二区精华液 | 亚洲第一av色| 日产精品久久久久久久性色| 波多野结衣中文字幕一区 | 欧美在线观看一二区| 精品毛片乱码1区2区3区 | 欧美日韩免费观看一区二区三区| 久久综合九色综合97婷婷| 亚洲一区在线观看视频| 久久精品国产久精国产| 这里只有精品视频在线观看| 亚洲电影一区二区| 蜜臀av国产精品久久久久| 不卡的av电影| 国产拍欧美日韩视频二区| 久久精品国产一区二区三区免费看| 在线观看免费一区| 18涩涩午夜精品.www| 丰满白嫩尤物一区二区| 久久久五月婷婷| 美国十次综合导航| 日韩一区二区三区电影| 亚州成人在线电影| 欧美色男人天堂| 一区二区日韩av| 欧美做爰猛烈大尺度电影无法无天| 亚洲欧美在线另类| 99精品国产91久久久久久| 国产精品色噜噜| 99国产精品国产精品久久| 99精品欧美一区二区蜜桃免费 | 一区二区三区国产| 不卡一区二区在线| 亚洲少妇30p| 成人av电影免费观看| 亚洲欧洲av色图| 91九色最新地址| 亚洲国产乱码最新视频| 777精品伊人久久久久大香线蕉| 亚洲超碰97人人做人人爱| 欧美精品久久久久久久多人混战| 日韩av不卡一区二区| 日韩欧美国产精品一区| 国产盗摄一区二区| 欧美国产97人人爽人人喊| 97久久人人超碰| 天堂影院一区二区| 欧美大度的电影原声| 精品国产一区二区三区四区四| 玉足女爽爽91| 久久综合九色欧美综合狠狠 | 久久综合色播五月| 成人蜜臀av电影| 一区二区三区.www| 日韩亚洲欧美成人一区| 国产jizzjizz一区二区| 亚洲综合丝袜美腿| 精品国产麻豆免费人成网站| 99这里都是精品| 日本不卡一区二区三区高清视频| 26uuu国产电影一区二区| 波多野洁衣一区| 日韩av一区二区三区| 国产精品乱人伦中文| 69堂成人精品免费视频| 国产不卡视频在线播放| 五月婷婷久久综合| 久久丝袜美腿综合| 欧美亚洲综合久久| 国产精品一区二区在线观看不卡 | 日韩成人免费在线| 国产精品久久久久一区二区三区| 欧美日韩精品欧美日韩精品| 国内精品视频666| 亚洲一区二区三区在线看| 精品久久久三级丝袜| 精品视频在线免费| 国产jizzjizz一区二区| 秋霞国产午夜精品免费视频| 亚洲天堂网中文字| 26uuu精品一区二区在线观看| 日本福利一区二区| 国产成人免费在线| 久久国产人妖系列| 亚洲国产成人高清精品| 国产精品久久三| 久久精品一区蜜桃臀影院| 欧美一区二区三区小说| 欧美日韩午夜精品| 色综合久久九月婷婷色综合| 国产专区综合网| 麻豆精品新av中文字幕| 日韩精品电影一区亚洲| 亚洲欧美视频在线观看| 国产精品女人毛片| 亚洲国产高清在线观看视频| 精品国产乱码久久久久久闺蜜| 宅男噜噜噜66一区二区66| 欧美日韩免费在线视频| 色诱亚洲精品久久久久久| eeuss国产一区二区三区| 国产成人一级电影| 国产高清久久久| 国产精品一级在线| 国产美女精品一区二区三区| 日韩精品一二三四| 日本最新不卡在线| 日本亚洲视频在线| 久久精品国产一区二区三| 美女一区二区久久| 国产在线一区二区| 国产精华液一区二区三区| 激情欧美日韩一区二区| 国产一区二区美女诱惑| 国产精品一二三区| 成人午夜看片网址| 99久久精品情趣| 欧美写真视频网站| 91麻豆精品国产91久久久久久 | www.66久久| 在线观看亚洲a| 欧美久久一二区| 欧美videos大乳护士334| 欧美草草影院在线视频| 久久精品亚洲精品国产欧美kt∨ | 91精选在线观看| 欧美电影免费提供在线观看| 久久久久久毛片| 亚洲欧美激情在线| 亚洲精品精品亚洲| 美女脱光内衣内裤视频久久影院| 国产一区不卡精品| 99久久免费视频.com| 91精品国产色综合久久ai换脸| 久久精品视频在线免费观看| 亚洲免费av高清| 日本不卡不码高清免费观看| 丰满亚洲少妇av| 欧美日韩你懂得| 中文字幕一区视频| 青青草成人在线观看| 成人黄色777网| 717成人午夜免费福利电影| 久久精品视频在线免费观看 | 久久久久久久性| 亚洲精品成人精品456| 精品在线视频一区| 91麻豆精品一区二区三区| 日韩欧美亚洲一区二区| 亚洲黄网站在线观看| 国产91综合一区在线观看| 欧美日韩精品电影| 国产精品久久久久毛片软件|