DelphiµÄSocket±à³ÌÒª·Ö¼¸²½£¿
DelphiµÄSocket±à³ÌÒª·Ö¼¸²½£¿
2008-12-20 02:03:24
¡¡±êÇ©£ºDelphi Socket ±à³Ì¡¡¡¡¡¡[ÍÆË͵½¼¼ÊõȦ]
ClientSocket ºÍServerSocket
¼¸¸öÖØÒªµÄÊôÐÔ:
1.clientºÍserver¶¼ÓÐportÊôÐÔ£¬ÐèÒªÒ»Ö²ÅÄÜ»¥ÏàͨÐÅ
2.clientÓÐAddressÊôÐÔ,ʹÓÃʱÌîд¶Ô·½(server)µÄIPµØÖ·
¼¸¸öÖØÒªµÄʼþ:
client: OnReadʼþ£¬µ±clientÊܵ½³å»÷ÏûϢʱÔÚOnReadʼþÖпÉÒÔ»ñµÃserver·¢Ë͹ýÀ´ÏûÏ¢¡£
Server: OnClientReadʼþ£¬ÓëÉÏÊöclientµÄ×÷ÓÃÏàͬ
·¢ËÍÐÅÏ¢£º
clienʹÓÃSocketClient1.Socket.SendBuf(charÀàÐ͵ÄÊý×é,ÐÅÏ¢³¤¶È);
serverʹÓÃSocketServer1.Socket.Connection[0].SendBuf(charÀàÐ͵ÄÊý×é,ÐÅÏ¢³¤¶È);
½ÓÊÕÐÅÏ¢
clienʹÓÃSocketClient1.Socket.ReceiveBuf(charÀàÐ͵ÄÊý×é,ÐÅÏ¢³¤¶È);
serverʹÓÃSocketServer1.Socket.Connection[0].ReceiveBuf(charÀàÐ͵ÄÊý×é,ÐÅÏ¢³¤¶È);
ʹÓÃsockets
Socket ¿Ø¼þÈÃÄ㽨Á¢Ò»¸öÀûÓÃTCP/IPºÍÓйصÄÐÒéÓëÆäËûϵͳ½øÐÐͨÐŵÄÓ¦Óá£Ê¹ÓÃSockets£¬ÄãÄܹ»¶ÁºÍдͨ¹ýËüÁ¬½ÓµÄÆäËû»úÆ÷£¬¶ø²»Óõ£ÐÄʵ¼ÊµÄÍøÂçÈí¼þµÄÏà¹Øϸ½Ú¡£SocketsÌṩ»ùÓÚTCP/IPÐÒéµÄÁ¬½Ó¡£³ý´ËÒÔÍ⻹ÄܺܺõŤ×÷£¬ÔÚÆäËûÏà¹ØµÄÐÒé¡£
Delphi ÌṩÄãдÍøÂç·þÎñÆ÷»ò¿Í»§Ó¦ÓóÌÐòÈ¥¶ÁºÍдÆäËûµÄϵͳ¡£Ò»¸ö·þÎñ»ò¿Í»§³ÌÐòͨ³£×¨×¢ÓÚÒ»¸öµ¥Ò»µÄ·þÎñÈ糬Îı¾´«ËÍÐÒ飨HTTP)»òÎļþ´«ÊäÐÒé (FTP)¡£Ê¹ÓÃserver sockets,Ò»¸öÓ¦ÓóÌÐò¿ÉÒÔÌṩÕâЩ·þÎñÖеÄÒ»¸öÈ¥Á¬½ÓÒ»¸öÏ£ÍûʹÓ÷þÎñµÄ¿Í»§³ÌÐò¡£Client socketsÔÊÐíÒ»¸öÓ¦ÓÃʹÓÃÕâЩ·þÎñÖеÄÒ»¸öÈ¥Á¬½ÓÌṩÕâ¸ö·þÎñµÄ·þÎñÓ¦Ó
Ïà¹ØÎĵµ£º
¹ý³ÌÎÞ·µ»ØÖµ£¬º¯ÊýÓзµ»ØÖµ¡£
procedure MyProc(m,n : Integer; o : String; p : Single = 2.5; q : String = 'Delphi');
ÈçÉÏÀýËùʾ£¬¹ý³ÌÉùÃ÷ºÍ¶¨ÒåÖУ¬¶à¸ö²ÎÊýÊÇÓ÷ֺŸô¿ªµÄ£¬µ«ÔÚµ÷ÓÃʱÊÇÓöººÅ¸ô¿ªµÄ ¡£eg£º
......
[code=Delphi(Pascal)]
unit uThreadPool;
{ aPool.AddRequest(TMyRequest.Create(RequestParam1, RequestParam2, ...)); }
interface
uses
Windows,
Classes;
// ÊÇ·ñ¼Ç¼ÈÕÖ¾
// {$DEFINE NOLOGS}
type
TCriticalSection = class(TObject)
protected
FSec ......
ËäÊÇÔ´´£¬µ«ÊÇÊDzο¼¹ý±ðÈ˵Ä×÷Æ·£¬È»ºó×Ô¼ºÖØÐÂдµÄ£¬Ä¿µÄÊÇÒª¸ø³õѧÕßÒ»¸ö¸üÈÝÒ×Ã÷°×¡£
ÓÃDELPHI´´½¨DLLÎļþ£¬·â×°´°ÌåµÄʵÏÖ·½·¨ÊµÀý£º
¼´Ò»¸ö³ÌÐò²»ÔÙÊǵ¥Ò»µÄÒ»¸öEXEÎļþÁË£¬¶øÊÇÓÉÒ»¸öEXEÎļþ¼ÓN¸öDLLÎļþ×é³É£¬ÕâÑù×öµÄÔÒòÊÇ·½±ãÒÔºóµÄά»¤Óë¸üУ¬Ò²ÊÇ¿çƽ̨¿ª·¢µÄÖØÒªÒ»²½¡£
1£¬ ´ò¿ªDELPHI£¬Ð½¨Ò»¸öDl ......
Ò»¡¢Formatº¯ÊýµÄÓ÷¨
FormatÊÇÒ»¸öºÜ³£Óã¬È´ÓÖËƺõºÜ·³µÄ·½·¨£¬±¾ÈËÊÔͼ¶ÔÕâ¸ö·½·¨µÄ°ïÖú½øÐÐһЩ·Ò룬ÈÃËüÓÐÒ»¸öÍêÕûµÄ¸Åò£¬ÒÔ¹©´ó¼Ò²éѯ֮Óãº
Ê×ÏÈ¿´ËüµÄÉùÃ÷£º
function Format(const Format: string; const Args: array of const): string; overload;
ÊÂʵÉÏFormat·½·¨ÓÐÁ½¸öÖÖÐÎʽ£¬ÁíÍâÒ»ÖÖÊÇÈý¸ö²ÎÊýµÄ£¬Ö ......
DelphiµÄ·½·¨ÀàÐÍÓУº
1.¾²Ì¬·½·¨ (Static) ĬÈÏÀàÐÍ£¬¿ÉÒÔÊ¡ÂԹؼü×Ö
2.ÐéÄâ·½·¨ (Virtual)
3.¶¯Ì¬·½·¨ (Dynamic)
4.ÏûÏ¢·½·¨ (Message)
5.³éÏó·¨·½ (Abstract)
=======================================================
1£©¾²Ì¬·½·¨[static]
¾²Ì¬·½·¨ÀàËÆÓÚͨ³£µÄ¹ý³ÌºÍº¯Êý£¬±àÒëÆ÷ÔÚ±àÒëʱ¾ÍÒÑÖ¸¶¨ÁËÊä³ö¸Ã·½· ......