青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Javen-Studio 咖啡小屋

http://javenstudio.org - C++ Java 分布式 搜索引擎
Naven's Research Laboratory - Thinking of Life, Imagination of Future

  C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  24 隨筆 :: 57 文章 :: 170 評(píng)論 :: 4 Trackbacks

SOCKET 的封裝

C++ 通用框架的設(shè)計(jì) 作者: naven

1?????????? SOCKET 封裝介紹

Socket 通訊程序估計(jì)現(xiàn)在大多數(shù)應(yīng)用系統(tǒng)都會(huì)涉及到,因?yàn)楝F(xiàn)在的世界是一個(gè)由 Internet 網(wǎng)絡(luò)連接的世界,任何個(gè)人電腦或服務(wù)都可能會(huì)有數(shù)據(jù)交換,通過(guò) TCP/UDP 這樣的 Socket 通訊協(xié)議進(jìn)行聯(lián)系。開(kāi)發(fā)這樣的通訊程序會(huì)是很普遍也很類似,每種操作系統(tǒng)都實(shí)現(xiàn)了 Socket 通訊庫(kù)并提供很相似的 API ,通訊步驟都遵循 RFC 規(guī)范。但是有些 API 的具體接口卻稍有不同,比如 Socket IO API win32 系統(tǒng)和 Unix 系統(tǒng)就不一樣, Win32 recv/send Unix 使用標(biāo)準(zhǔn)統(tǒng)一的 read/write ,而且 socket 句柄在不同操作系統(tǒng)處理也不一樣,等等這些都造成編寫(xiě)跨平臺(tái)的 Socket 應(yīng)用不太容易。另外編寫(xiě)服務(wù)器和客戶端的處理步驟也很繁瑣, IP 地址和域名的轉(zhuǎn)換也很麻煩,所以實(shí)現(xiàn)一個(gè)標(biāo)準(zhǔn)統(tǒng)一使用更簡(jiǎn)潔的 API 非常有用。本 C++ 框架基本參考 Java Socket 相關(guān)類實(shí)現(xiàn)了類似封裝,除了 ServerSocket 實(shí)現(xiàn)稍有不同,其他原理和方法基本類似。用它編寫(xiě)網(wǎng)絡(luò)應(yīng)用基本不用考慮底層的協(xié)議處理,使用非常容易,代碼也更簡(jiǎn)潔易讀。

?

主要有如下一些類

?

class Socket ?????????????????????? ??????????????????????????? 代表一個(gè) TCP 連接的 Socket 對(duì)象

???????? class DatagramSocket??????????????????????????????????? 代表一個(gè) UDP 連接的 Socket 對(duì)象(暫未實(shí)現(xiàn))

???????? class MulticastSocket??????????????????????????????????? 一個(gè) DatagramSocket 的子類用于多播(暫未實(shí)現(xiàn))

class SocketAcceptor??????????????????????????????????? 一個(gè) TCP 服務(wù)端的接收器

class SocketConnector????????????????????????????????? 一個(gè) TCP 客戶端的連接器

???????? class SocketInputStream?????????????????????????????? 一個(gè) Socket 連接的輸入流

???????? class SocketOutputStream??????????????????????????? 一個(gè) Socket 連接的輸出流

???????? class SocketReader??????????????????????????????????????? 一個(gè) Socket 連接的讀操作器

???????? class SocketWriter????????????????????????????????????????? 一個(gè) Socket 連接的寫(xiě)操作器

?

Socket 的意思是在網(wǎng)絡(luò)的機(jī)器之間建立一個(gè)通信線路。通過(guò) TCP Sockets 發(fā)送或接收的操作時(shí)通過(guò) InputStream OutputStream 流處理的, Socket 類的 getInputStream getOutputStream 可以取得該 Socket 連接的輸入 / 輸出流對(duì)象。 SocketAcceptor 是用于服務(wù)器端的接收器,它處于接收的狀態(tài)時(shí)會(huì)阻塞,直到接收到客戶端的連接請(qǐng)求,這時(shí)就會(huì)創(chuàng)建一個(gè) Socket 對(duì)象代表該服務(wù)器到此客戶端的連接。而對(duì)應(yīng)的 SocketConnector 是用于客戶端的連接器,它向服務(wù)端發(fā)出連接請(qǐng)求,如果服務(wù)器允許連接,則也同時(shí)建立一個(gè) Socket 對(duì)象表示它到服務(wù)器端的連接,這時(shí)就可以獲取輸入 / 輸出流對(duì)象進(jìn)行 Socket 通訊了。

2?????????? Hello World!

下面的程序示例如何用上面的類進(jìn)行 Scoket 通訊:

這是服務(wù)端的實(shí)現(xiàn)

void ?servertest()?
{
????
// ?定義一個(gè)接收器綁定?8000?端口
????SocketAcceptor?sa( 8000 );?
????
while ( 1 )?
{
???????
// ?阻塞等待連接請(qǐng)求
????????Socket?sk? = ?sa.accept();?
????????
// ?獲取此連接的讀操作器和寫(xiě)操作器
????????Reader? & rd? = ?sk.getReader();?
????????Writer?
& wr? = ?sk.getWriter();?
????????String?s;?
????????
// ?從客戶端讀取?10?個(gè)字節(jié)
????????rd.read(s,? 10 );?
????????
// ?向客戶端寫(xiě)信息
????????wr.write(“read?ok”);?
????????
// ?關(guān)閉連接
????????sk.close();?
}

}

這是客戶端的實(shí)現(xiàn)

void ?clienttest()
{
????
// ?定義一個(gè)連接器
SocketConnector?sc;?
// ?連接指定的服務(wù)器地址及端口,?返回一個(gè)Socket對(duì)象
Socket?sk? = ?sc.connect(“l(fā)ocalhost”,? 8000 );?
// ?如果已成功連上
???? if (?sk.isConnected()?)?
{
????
// ?獲取此連接的讀操作器和寫(xiě)操作器
????????Reader & ?reader? = ?sk.getReader();?
????????Writer
& ?writer? = ?sk.getWriter();?
????????
// ?可以在讀操作器上建立一個(gè)帶緩沖的讀操作器
????????BufferedReader?rd(reader);
????????
// ?向服務(wù)器發(fā)送信息
????????writer.write(“hello?server”);
????????
// ?接收信息,?帶緩沖的讀操作器可以讀取一行
????????rd.readLine(s);
????????
// ?關(guān)閉連接
????????sk.close();
????}

}


1?????????? Socket

此類定義一個(gè)表示 Socket 連接的類,一個(gè) Socket 是一個(gè)為在兩臺(tái)機(jī)器間通信的端點(diǎn)。一個(gè) Socket 類的真實(shí)行為是通過(guò)一個(gè) SocketImpl 類的詩(shī)體執(zhí)行的。一個(gè)應(yīng)用程序可以通過(guò)改變 Socket Factory 來(lái)創(chuàng)建 Socket 的具體實(shí)現(xiàn),以適應(yīng)本地的局域網(wǎng)防火墻。

Socket 類成員和主要接口定義如下:

?

class ?Socket?:? public ?AbstractFile?
{
protected :?
????
/* *
?????*?The?implementation?of?this?Socket.
?????
*/

????SocketImplAutoPtr?_impl;?

????
/* *
?????*?Various?states?of?this?socket.
?????
*/

????BOOL?_connected;?
????BOOL?_closed;?
????BOOL?_shutIn;?
BOOL?_shutOut;

public :?
????
/* *
?????*?Creates?an?unconnected?socket,?with?the
?????*?system-default?type?of?SocketImpl.
?????
*/

Socket();

????
/* *
?????*?Returns?an?input?stream?for?this?socket.
?????*
?????*?@return?????an?input?stream?for?reading?bytes?from?this?socket.
?????
*/

????InputStream
& ?getInputStream();

????
/* *
?????*?Gets?an?Reader?for?this?socket.
?????
*/

????Reader
& ?getReader();

????
/* *
?????*?Returns?an?output?stream?for?this?socket.
?????*
?????*?@return?????an?output?stream?for?writing?bytes?to?this?socket.
?????
*/

????OutputStream
& ?getOutputStream();

????
/* *
?????*?Gets?an?Writer?for?this?socket.
?????
*/

????Writer
& ?getWriter();?

????
/* *
?????*?Enable/disable?the?option?specified?by?<I>optID</I>.??If?the?option
?????*?is?to?be?enabled,?and?it?takes?an?option-specific?"optval",??this?is
?????*?passed?in?<I>value</I>.??The?actual?type?of?value?is?option-specific,
?????*?and?it?is?an?error?to?pass?something?that?isn't?of?the?expected?type:
?????*?<BR>
?????*
?????*?@param?optID?identifies?the?option
?????*?@param?level?[in]?Level?at?which?the?option?is?defined;?the?supported?levels?
?????*??????????????include?SOL_SOCKET?and?IPPROTO_TCP.?
?????*?@param?optval?[in]?Pointer?to?the?buffer?in?which?the?value?for?the?requested?
?????*??????????????option?is?to?be?returned.
?????*?@param?optlen?[in]?Pointer?to?the?size?of?the?optval?buffer,?in?bytes.?
?????*?@return?0?If?no?error?occurs,?Otherwise,?a?value?of?SOCKET_ERROR(-1)?is?returned,?
?????*??????????and?a?specific?error?code?can?be?retrieved?by?socketerrno.
?????*?@see?#getOption(int)
?????
*/

????
int ?setOption( int ?optID,? int ?level,? const ? void ? * optval,? int ?optlen);

????
/* *
?????*?Fetch?the?value?of?an?option.
?????*?Binary?options?will?return?java.lang.Boolean(true)
?????*?if?enabled,?java.lang.Boolean(false)?if?disabled,?e.g.:
?????*?<BR>
?????*
?????*?@param?optID?an?<code>int</code>?identifying?the?option?to?fetch
?????*?@param?level?[in]?Level?at?which?the?option?is?defined;?the?supported?levels?
?????*??????????????include?SOL_SOCKET?and?IPPROTO_TCP.?
?????*?@param?optval?[out]?Pointer?to?the?buffer?in?which?the?value?for?the?requested?
?????*??????????????option?is?to?be?returned.
?????*?@param?optlen?[in,?out]?Pointer?to?the?size?of?the?optval?buffer,?in?bytes.?
?????*?@return?0?If?no?error?occurs,?Otherwise,?a?value?of?SOCKET_ERROR(-1)?is?returned,?
?????*??????????and?a?specific?error?code?can?be?retrieved?by?socketerrno.
?????*?@see?#setOption(int,?java.lang.Object)
?????
*/

????
int ?getOption( int ?optID,? int ?level,? void ? * optval,? int ? * optlen);

????
/* *
?????*?Closes?this?socket.
?????*?<p>
?????*?Any?thread?currently?blocked?in?an?I/O?operation?upon?this?socket
?????*?will?throw?a?{@link?SocketException}.
?????*?<p>
?????*?Once?a?socket?has?been?closed,?it?is?not?available?for?further?networking
?????*?use?(i.e.?can't?be?reconnected?or?rebound).?A?new?socket?needs?to?be
?????*?created.
?????*
?????*?<p>?If?this?socket?has?an?associated?channel?then?the?channel?is?closed
?????*?as?well.
?????*
?????
*/

????
void ?close();

}
;


?

1?????????? SocketAcceptor

此類實(shí)現(xiàn)一個(gè)用于服務(wù)器端接收連接的類。一個(gè)SocketAcceptor對(duì)象等待來(lái)自網(wǎng)絡(luò)的連接請(qǐng)求,它執(zhí)行一些基于請(qǐng)求的操作,并且可能返回一些信息給請(qǐng)求者。連接成功后SocketAcceptor會(huì)生成一個(gè)Socket對(duì)象用于網(wǎng)絡(luò)通訊。

SocketAcceptor類成員和主要接口定義如下:

?

class?SocketAcceptor
{
protected:?
????
/**
?????*?The?factory?for?all?server?sockets.
?????
*/

????
static?SocketImplFactoryAutoPtr?_factory;?

????
/**
?????*?The?implementation?of?this?Socket.
?????
*/

????SocketImplAutoPtr?_impl;?

????
/**
?????*?Various?states?of?this?socket.
?????
*/

????BOOL?_bound;?
????BOOL?_created;?
????BOOL?_closed;?
????BOOL?_stream;?

public:?
????
/**
?????*?Creates?a?socket?acceptor?with?default?stream?type.
?????*?<p>
?????
*/

????SocketAcceptor();?

????
/**
?????*?Creates?a?socket?acceptor?with?specified?stream?type,?
?????*?bound?to?the?specified?port?and?host.?A?port?of?
?????*?<code>0</code>?creates?a?socket?on?any?free?port.?
?????*?<p>
?????*?The?maximum?queue?length?for?incoming?connection?indications?(a?
?????*?request?to?connect)?is?set?to?<code>50</code>.?If?a?connection?
?????*?indication?arrives?when?the?queue?is?full,?the?connection?is?refused.
?????*?<p>
?????*?If?the?application?has?specified?a?server?socket?factory,?that?
?????*?factory's?<code>createSocketImpl</code>?method?is?called?to?create?
?????*?the?actual?socket?implementation.?Otherwise?a?"plain"?socket?is?created.
?????*?<p>
?????*
?????*?@param??????host?the?host?address?the?server?will?bind?to
?????*?@param??????port??the?port?number,?or?<code>0</code>?to?use?any
?????*???????????????????free?port.
?????*?@param??????stream????if?<code>true</code>,?create?a?stream?socket;
?????*???????????????????????otherwise,?create?a?datagram?socket.
?????*?@param??????backlog?the?listen?backlog
?????
*/

SocketAcceptor(
const?String?&host,?int?port,?BOOL?stream?=?TRUE);

????
/**
?????*?Binds?the?<code>ServerSocket</code>?to?a?local?address
?????*?(IP?address?and?port?number).
?????*?<P>
?????*?The?<code>backlog</code>?argument?must?be?a?positive
?????*?value?greater?than?0.?If?the?value?passed?if?equal?or?less
?????*?than?0,?then?the?default?value?will?be?assumed.
?????*?@param?port?the?local?TCP?port
?????*?@param?backlog?the?listen?backlog
?????*?@return?0?If?no?error?occurs,?Otherwise,?a?value?of?
?????*??????????SOCKET_ERROR(-1)?is?returned
?????
*/

????
int?bind(int?port,?int?backlog?=?LISTENQ);

????
/**
?????*?Listens?for?a?connection?to?be?made?to?this?socket?and?accepts?
?????*?it.?The?method?blocks?until?a?connection?is?made.?
?????*
?????*?<p>A?new?Socket?<code>s</code>?is?created?and,?if?there?
?????*?is?a?security?manager,?
?????*?the?security?manager's?<code>checkAccept</code>?method?is?called
?????*?with?<code>s.getInetAddress().getHostAddress()</code>?and
?????*?<code>s.getPort()</code>
?????*
?????*?@param?timeout??timeout?to?accept?in?ms.?
?????*?@return?the?new?Socket
?????
*/

????Socket?accept(
int?timeout);?

????
/**
?????*?Closes?this?socket?acceptor.
?????*?<p>
?????*?Any?thread?currently?blocked?in?an?I/O?operation?upon?this?socket
?????*?will?throw?a?{@link?SocketException}.
?????*?<p>
?????*?Once?a?socket?has?been?closed,?it?is?not?available?for?further?networking
?????*?use?(i.e.?can't?be?reconnected?or?rebound).?A?new?socket?needs?to?be
?????*?created.
?????*
?????*?<p>?If?this?socket?has?an?associated?channel?then?the?channel?is?closed
?????*?as?well.
?????*
?????
*/

????
void?close();

}
;

1?????????? SocketConnector

此類實(shí)現(xiàn)一個(gè)用于客戶器端連接服務(wù)的類。一個(gè)SocketConnector對(duì)象可以向指定的服務(wù)地址和端口發(fā)出的連接請(qǐng)求,它執(zhí)行一些基于請(qǐng)求的操作,并且可能返回一些信息。連接成功后SocketConnector會(huì)生成一個(gè)Socket對(duì)象用于網(wǎng)絡(luò)通訊。

SocketConnector類成員和主要接口定義如下:

class?SocketConnector
{
protected:?
????
/**
?????*?The?factory?for?all?server?sockets.
?????
*/

????
static?SocketImplFactoryAutoPtr?_factory;?

????
/**
?????*?The?implementation?of?this?Socket.
?????
*/

????SocketImplAutoPtr?_impl;?

????
/**
?????*?Various?states?of?this?socket.
?????
*/

????BOOL?_bound;?
????BOOL?_created;?
????BOOL?_closed;?
????BOOL?_stream;;?

public:?
????
/**
?????*?Creates?a?socket?connector?with?specified?stream?type.
?????*?default?is?Creates?a?stream?socket?connector.?
?????*?<p>
?????*
?????*?@param??????stream????if?<code>true</code>,?create?a?stream?socket;
?????*???????????????????????otherwise,?create?a?datagram?socket.
?????
*/

????SocketConnector(BOOL?stream?
=?TRUE);

????
/**
?????*?Creates?a?socket?and?connects?it?to?the?specified?port?on
?????*?the?specified?host.
?????*?@param?host?the?specified?host
?????*?@param?port?the?specified?port
?????*?@param?timeout?the?timeout?value?in?milliseconds,?or?zero?for?no?timeout.
?????*??????????-1?will?use?default?timeout.
?????*?@return?the?new?Socket
?????
*/

Socket?connect(
const?String?&host,?int?port,?int?timeout?=?-1);

????
/**
?????*?Closes?this?socket?connector.
?????*?<p>
?????*?Any?thread?currently?blocked?in?an?I/O?operation?upon?this?socket
?????*?will?throw?a?{@link?SocketException}.
?????*?<p>
?????*?Once?a?socket?has?been?closed,?it?is?not?available?for?further?networking
?????*?use?(i.e.?can't?be?reconnected?or?rebound).?A?new?socket?needs?to?be
?????*?created.
?????*
?????*?<p>?If?this?socket?has?an?associated?channel?then?the?channel?is?closed
?????*?as?well.
?????*
?????
*/

????
void?close();

}
;

1?????????? SocketInputStream

這個(gè)類類似與其他InputStreamFileInputStream類,是InputStream接口類的一個(gè)實(shí)現(xiàn),執(zhí)行Socket流的讀取操作,實(shí)現(xiàn)的接口均是最基礎(chǔ)的操作,如讀取一個(gè)byte字節(jié)的數(shù)據(jù),或者讀取指定長(zhǎng)度的數(shù)據(jù)。

SocketInputStream類成員和主要接口定義如下:

class?SocketInputStream?:?public?InputStream
{
protected:?
????
/**
?????*?Pointer?to?the?implementation?of?this?SocketImpl.
?????
*/

????PlainSocketImpl?
*_impl;?

????
/**
?????*?Pointer?to?the?implementation?of?this?Socket.
?????
*/

????Socket?
*_socket;?

????BOOL?_eof;?
BOOL?_closing;

????
/**
?????*?Creates?a?new?SocketInputStream.?Can?only?be?called
?????*?by?a?Socket.?This?method?needs?to?hang?on?to?the?owner?Socket?so
?????*?that?the?fd?will?not?be?closed.
?????*?@param?impl?the?implemented?socket?input?stream
?????
*/

????SocketInputStream(PlainSocketImpl?
&impl);

public:?
????
/**
?????*?Check?current?SocketInputStream?object?if?is?opened.?
?????*
?????*?@return??TRUE?if?opened?else?return?FALSE
?????
*/

????BOOL?isOpened();

????
/**
?????*?Reads?a?byte?of?data?from?this?input?stream.?This?method?blocks
?????*?if?no?input?is?yet?available.
?????*
?????*?@return?????the?next?byte?of?data,?or?<code>-1</code>?if?the?end?of?the
?????*?????????????file?is?reached.
?????
*/

????
int?read();?

????
/**
?????*?Reads?up?to?<code>len</code>?bytes?of?data?from?this?input?stream
?????*?into?an?array?of?bytes.?This?method?blocks?until?some?input?is
?????*?available.
?????*
?????*?@param??????b?????the?buffer?into?which?the?data?is?read.
?????*?@param??????off???the?start?offset?of?the?data.
?????*?@param??????len???the?maximum?number?of?bytes?read.
?????*?@return?????the?total?number?of?bytes?read?into?the?buffer,?or
?????*?????????????<code>0</code>?if?there?is?no?more?data?because?the?end?of
?????*?????????????the?file?has?been?reached,?or?-1?if?read?error.
?????
*/

????
int?read(void?*b,?int?off,?int?len);

????
/**
?????*?Reads?up?to?<code>len</code>?bytes?of?data?from?this?input?stream
?????*?into?an?array?of?bytes.?This?method?blocks?until?some?input?is
?????*?available.
?????*
?????*?@param??????b?????the?buffer?into?which?the?data?is?read.
?????*?@param??????len???the?maximum?number?of?bytes?read.
?????*?@return?????the?total?number?of?bytes?read?into?the?buffer,?or
?????*?????????????<code>0</code>?if?there?is?no?more?data?because?the?end?of
?????*?????????????the?file?has?been?reached,?or?-1?if?read?error.
?????
*/

????
int?read(void?*b,?int?len);

????
/**
?????*?Skips?over?and?discards?<code>n</code>?bytes?of?data?from?the
?????*?input?stream.?The?<code>skip</code>?method?may,?for?a?variety?of
?????*?reasons,?end?up?skipping?over?some?smaller?number?of?bytes,
?????*?possibly?<code>0</code>.?The?actual?number?of?bytes?skipped?is?returned.
?????*
?????*?@param??????n???the?number?of?bytes?to?be?skipped.
?????*?@return?????the?actual?number?of?bytes?skipped.
?????
*/

????
long?skip(long?n);?

????
/**
?????*?Returns?the?number?of?bytes?that?can?be?read?from?this?file?input
?????*?stream?without?blocking.
?????*
?????*?@return?????the?number?of?bytes?that?can?be?read?from?this?file?input
?????*?????????????stream?without?blocking.
?????
*/

????
int?available();?

????
/**
?????*?Closes?this?file?input?stream?and?releases?any?system?resources
?????*?associated?with?the?stream.
?????*
?????*?<p>?If?this?stream?has?an?associated?channel?then?the?channel?is?closed
?????*?as?well.
?????
*/

????
void?close();

}
;


?

1?????????? SocketOutputStream

這個(gè)類類似與其他OutputStreamFileOutputStream類,是OutputStream接口類的一個(gè)實(shí)現(xiàn),執(zhí)行Socket流的寫(xiě)操作,實(shí)現(xiàn)的接口均是最基礎(chǔ)的操作,如寫(xiě)一個(gè)byte字節(jié)的數(shù)據(jù),或者寫(xiě)指定長(zhǎng)度的數(shù)據(jù)。

SocketOutputStream類成員和主要接口定義如下:

?

class?SocketOutputStream?:?public?OutputStream
{
protected:?
????
/**
?????*?Pointer?to?the?implementation?of?this?SocketImpl.
?????
*/

????PlainSocketImpl?
*_impl;?

????
/**
?????*?Pointer?to?the?implementation?of?this?Socket.
?????
*/

Socket?
*_socket;

????
/**
?????*?Creates?a?new?SocketOutputStream.?Can?only?be?called
?????*?by?a?Socket.?This?method?needs?to?hang?on?to?the?owner?Socket?so
?????*?that?the?fd?will?not?be?closed.
?????*?@param?impl?the?implemented?socket?input?stream
?????
*/

????SocketOutputStream(PlainSocketImpl?
&impl);

public:?
????
/**
?????*?Check?current?SocketInputStream?object?if?is?opened.?
?????*
?????*?@return??TRUE?if?opened?else?return?FALSE
?????
*/

????BOOL?isOpened();?

????
/**
?????*?Report?position?in?output?stream.
?????
*/
?
long?tellp();

????
/**
?????*?Writes?the?specified?byte?to?this?file?output?stream.?Implements?
?????*?the?<code>write</code>?method?of?<code>OutputStream</code>.
?????*
?????*?@param?b???the?byte?to?be?written.
?????
*/

????SocketOutputStream
&?write(int?b);?

????
/**
?????*?Writes?<code>len</code>?bytes?from?the?specified?byte?array?
?????*?starting?at?offset?<code>off</code>?to?this?file?output?stream.?
?????*
?????*?@param??????b?????the?data.
?????*?@param??????len???the?number?of?bytes?to?write.
?????
*/

????SocketOutputStream
&?write(const?void?*b,?int?len);?

????
/**
?????*?Writes?<code>len</code>?bytes?from?the?specified?byte?array?
?????*?starting?at?offset?<code>off</code>?to?this?file?output?stream.?
?????*
?????*?@param??????b?????the?data.
?????*?@param??????off???the?start?offset?in?the?data.
?????*?@param??????len???the?number?of?bytes?to?write.
?????
*/

????SocketOutputStream
&?write(const?void?*b,?int?off,?int?len);?

????
/**
?????*?Flushes?this?output?stream?and?forces?any?buffered?
?????*?output?bytes?to?be?written?out.
?????
*/

????
void?flush();?

????
/**
?????*?Closes?this?file?out?stream?and?releases?any?system?resources
?????*?associated?with?the?stream.
?????*
?????*?<p>?If?this?stream?has?an?associated?channel?then?the?channel?is?closed
?????*?as?well.
?????
*/

????
void?close();

}
;


?

1?????????? SocketReader類和SocketWriter

SocketReader類實(shí)現(xiàn)了一個(gè)對(duì)Socket流讀設(shè)備即SocketInputStream的讀取器,它實(shí)現(xiàn)了Reader接口類的方法,所以具有與其它Reader相同的功能,也可以與其它一些讀操作器如BufferedReader配合使用以達(dá)到一些更高級(jí)的功能。

SocketWriter 類則實(shí)現(xiàn)了一個(gè)對(duì)Socket流寫(xiě)設(shè)備即SocketOutputStream的寫(xiě)操作器,它實(shí)現(xiàn)了Writer接口類的方法,所以具有與其它Writer相同的功能,如進(jìn)行一些operator <<運(yùn)算符的操作等。

詳細(xì)例子請(qǐng)參考 httptest.cpp 范例程序。

?

?

?

C++通用框架的設(shè)計(jì)作者:naven 日期:2006-8-10


?

posted on 2006-08-10 00:46 Javen-Studio 閱讀(8624) 評(píng)論(15)  編輯 收藏 引用

評(píng)論

# re: SOCKET的封裝 2006-08-10 06:57 萬(wàn)連文
代碼呢???可以給我一份???
wlwlxj@gmail.com
謝謝  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2006-08-10 10:23 Javen-Studio
首頁(yè)可以下載試用版本,源碼等我完成后會(huì)open source的,thx  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2006-08-10 18:16 子彈
不錯(cuò),

我最近也在學(xué)習(xí)NETWORK編程

希望能與你交流  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2006-08-10 18:22 navy
好啊,一起學(xué)習(xí)~  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2006-08-15 12:21 可冰
不錯(cuò)。
不知道naven了解ACE不,感覺(jué)有一點(diǎn)類似。不過(guò)我覺(jué)得更像JAVA。  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2006-08-15 13:56 Javen-Studio
是啊,我就是學(xué)習(xí)了一些ACE的設(shè)計(jì)想法做的,接口都仿照java  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2011-07-22 14:17 this 王
能給我份源碼?  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2012-02-28 22:13 FrankWang
380330439@qq.com
能給我一份源代碼嗎?
我也在學(xué)這個(gè)。  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝[未登錄](méi) 2012-04-30 14:59 cc
371549734@qq.com
如果可以,麻煩也給我一份 謝謝了  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2012-11-12 12:38 sammy
看了你的文章,感覺(jué)封裝的不錯(cuò)。能給我一份源代碼嗎?
sammylymhk@yahoo.com.cn  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2013-04-01 18:33 楊平
有源代碼嗎?請(qǐng)轉(zhuǎn)一份給我啊,qq:448086006@qq.com,多謝!  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2014-05-08 16:55 weiqinyu
寫(xiě)的真好。能發(fā)給我一份嗎?weiqinyu2005@163.com  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2015-03-21 18:32 陳甜
寫(xiě)的真好。能發(fā)給我一份嗎?283063526@qq.com  回復(fù)  更多評(píng)論
  

# re: SOCKET的封裝 2015-07-19 17:29 莫莫
看了你的文章,感覺(jué)封裝的不錯(cuò)。能給我一份源代碼嗎?@Javen-Studio
gypzfabc@126.com  回復(fù)  更多評(píng)論
  


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美激情91| 亚洲精品欧洲| 亚洲免费在线视频| 午夜亚洲福利在线老司机| 欧美激情第五页| 久久成人免费| 亚洲午夜激情在线| 美女图片一区二区| 国产一区二区三区直播精品电影| 久热国产精品| 香港久久久电影| 亚洲性感美女99在线| 亚洲精品久久久久久久久久久久| 99国产精品| 亚洲国产视频一区二区| 影音先锋日韩有码| 一区二区三区在线观看视频| 国产欧美日韩不卡| 欧美精品手机在线| 欧美一二三区精品| 亚洲欧美日韩精品久久| 在线视频一区观看| 欧美日韩在线播放一区| 嫩草成人www欧美| 欧美另类综合| 国产欧美日韩亚州综合| 亚洲电影一级黄| 亚洲一区二区三区高清不卡| 午夜免费在线观看精品视频| 久久人人97超碰精品888| 欧美福利视频在线观看| 在线综合亚洲欧美在线视频| 久久精品二区三区| 欧美性做爰毛片| 亚洲国产日韩一区| 性色av香蕉一区二区| 亚洲大片在线| 欧美在线观看天堂一区二区三区| 免费成人av在线看| 国产一区二区三区网站| 一本色道精品久久一区二区三区 | 国产亚洲精品资源在线26u| 亚洲激情社区| 久久综合伊人77777麻豆| 最新国产成人av网站网址麻豆| 亚洲性线免费观看视频成熟| 午夜精品国产精品大乳美女| 欧美片网站免费| 亚洲国产婷婷| 久久天堂国产精品| 午夜精品视频在线| 欧美日韩精品国产| 亚洲精品日韩精品| 欧美肥婆在线| 久久久久久亚洲综合影院红桃| 欧美午夜美女看片| 亚洲午夜av在线| 日韩视频在线观看国产| 免费永久网站黄欧美| 影音先锋国产精品| 久久久久国产一区二区| 欧美日韩调教| 国产精品国产三级国产专区53 | 国产日韩三区| 中文一区二区在线观看| 99精品福利视频| 国产精品亚洲一区| 免费观看成人www动漫视频| 欧美成人午夜激情| 欧美一二三区精品| 欧美日韩亚洲精品内裤| 国产精品99久久久久久有的能看| 亚洲精品国偷自产在线99热| 欧美午夜精品久久久| 亚洲成色777777女色窝| 国产精品久久久久久久久动漫| 久久黄金**| 亚洲精品一区二区网址| 欧美国产日韩二区| 欧美.www| 在线观看日韩欧美| 午夜在线播放视频欧美| 亚洲视频网在线直播| 久久久在线视频| 久久久之久亚州精品露出| 欧美三级不卡| 亚洲电影在线看| 在线观看三级视频欧美| 欧美一级视频精品观看| 国产精品久久久999| 亚洲欧洲精品一区二区三区| 亚洲激情校园春色| 欧美黄色片免费观看| 国产精品视频第一区| 一本久久精品一区二区| 一区二区三区国产在线| 欧美日韩国内| 午夜精品久久久久久久久久久久久| 亚洲婷婷综合久久一本伊一区| 国产精品久久久久9999高清| 亚洲精品国产精品久久清纯直播| 亚洲日本一区二区| 欧美二区视频| 亚洲网友自拍| 欧美不卡一卡二卡免费版| 亚洲电影免费观看高清完整版在线观看| 久久久久成人精品| 一区二区日韩精品| 免费日韩av| 欧美一区二区三区精品电影| 亚洲电影免费观看高清完整版在线观看 | 亚洲综合导航| 国产伦理一区| 欧美成人官网二区| 亚洲欧美成人一区二区三区| 久色成人在线| 在线视频亚洲欧美| 亚洲成色www久久网站| 免费日韩av电影| 欧美一级一区| 亚洲制服av| 欧美金8天国| 久久一区国产| 亚洲影视在线播放| 亚洲欧美日韩久久精品| 亚洲欧美中文另类| 欧美一区二区视频97| 亚洲欧美中文在线视频| 国产午夜精品理论片a级探花 | 91久久线看在观草草青青| 久久综合伊人| 亚洲精品一区二区三区av| 亚洲日本视频| 在线亚洲伦理| 久久久www| 欧美亚洲一区在线| 久久久久久久精| 欧美夫妇交换俱乐部在线观看| 免费日本视频一区| 亚洲欧洲日韩综合二区| 亚洲一区二区三区777| 欧美亚洲免费电影| 欧美成人中文| 国产精品久久午夜夜伦鲁鲁| 亚洲一区国产视频| 久久综合色综合88| 亚洲欧洲日本mm| 午夜精品短视频| 亚洲精品在线三区| 久久久久青草大香线综合精品| 欧美激情一二三区| 亚洲高清在线观看| 亚洲免费影视第一页| 久久一本综合频道| 亚洲视频狠狠| 欧美日韩日本国产亚洲在线| 最近中文字幕mv在线一区二区三区四区| 久久久久久久高潮| 国产日韩在线一区| 国产一区二区在线观看免费| 伊人婷婷久久| 玖玖综合伊人| 午夜在线电影亚洲一区| 国产三区二区一区久久| 久久久噜久噜久久综合| 久久久精彩视频| 国产日韩精品一区观看| 日韩午夜在线电影| 国产精品激情av在线播放| 亚洲欧美日韩精品久久奇米色影视| 亚洲高清视频在线观看| 欧美大片免费久久精品三p| 999在线观看精品免费不卡网站| 欧美在线观看你懂的| 欧美国产大片| 国产精品高潮呻吟久久| 亚洲午夜国产成人av电影男同| 欧美国产欧美亚洲国产日韩mv天天看完整 | 一区二区高清视频| 日韩一级二级三级| 国产一区二区中文字幕免费看| 欧美在线一二三区| 久久亚洲国产成人| 亚洲女ⅴideoshd黑人| 亚洲欧美日韩直播| 狠狠久久亚洲欧美| 一区二区三区成人| 国产一区二区三区在线观看精品 | 欧美性jizz18性欧美| 久久久最新网址| 国产精品人人做人人爽| 国产女优一区| 久久久久久夜| 欧美三级电影大全| 亚洲国产精品久久久久| 亚洲久久在线| 欧美一区二区日韩一区二区| 欧美精品一区二区三区一线天视频| 久久午夜精品| 尤物视频一区二区|