SocketNet  1.0
A Socket Networking (C/S) Library
SocketNet.TcpServer クラス

マルチスレッド TCP サーバ。 [詳解]

SocketNet.TcpServer の継承関係図
Inheritance graph
SocketNet.TcpServer 連携図
Collaboration graph

公開メンバ関数

 TcpServer (int port, Packet packet)
 コンストラクタ。 [詳解]
 
 TcpServer (IPAddress ipAddress, int port, Packet packet)
 コンストラクタ。 [詳解]
 
void Dispose ()
 オブジェクトに関連付けられたリソースを解放します。 [詳解]
 
async Task Start ()
 TCPサーバをスタートします。 [詳解]
 
void Stop ()
 Tcpサーバを停止します。 [詳解]
 
void CloseConnection (TcpConnection connection)
 アクティブな接続をクローズします。 [詳解]
 

静的公開変数類

static readonly int MaxPendingConnections = 3
 ペンディングできる接続の最大数。 [詳解]
 

プロパティ

IPAddress IPAddress [get, private set]
 Tcpサーバにバインドされている IP アドレスを取得します。 [詳解]
 
int Port [get, private set]
 Tcpサーバにバインドされているポート番号を取得します。 [詳解]
 
bool IsRunning [get]
 サーバの状態を取得します。 [詳解]
 
int ActiveConnectionCount [get]
 アクティブな接続の数を取得します。 [詳解]
 
ReadOnlyCollection< TcpConnectionActiveConnections [get]
 アクティブな接続のリストを取得します。 [詳解]
 

イベント

EventHandler< TcpConnectionEventArgsConnected
 接続が確立した時に発行されます。 [詳解]
 
EventHandler< TcpConnectionEventArgsDisconnected
 接続が切断された時に発行されます。 [詳解]
 
EventHandler< TcpDataReceivedEventArgsDataReceived
 データを受信した時に発行されます。 [詳解]
 

非公開メンバ関数

void Dispose (bool disposing)
 オブジェクトに関連付けられたリソースを解放します。 [詳解]
 
void OnConnected (TcpConnectionEventArgs e)
 接続イベントを発行します。 [詳解]
 
void OnDisconnected (object sender, TcpConnectionEventArgs e)
 切断イベントを発行します。 [詳解]
 
void OnDataReceived (object sender, TcpDataReceivedEventArgs e)
 データ受信イベントを発行します。 [詳解]
 
void CloseMarkedConnections ()
 マークされた接続をクローズします。 [詳解]
 

非公開変数類

readonly Packet Packet
 
TcpListener tcpListener
 
List< TcpConnectionclientConnections
 
List< TcpConnectionconnectionsToClose
 
volatile bool isShuttingDown
 
volatile bool acceptingConnections
 
bool disposed = false
 

詳解

マルチスレッド TCP サーバ。

このサーバは、TCPメッセージを非同期的に受信します。 Start メソッドで待ち受けを開始します。 接続が確立すると Connected イベントが発行されます。 接続が切断されると Disconnected イベントが発行されます。 メッセージを完全に受信すると DataReceived イベントが発行されます。

受信するメッセージについては TcpConnection クラスの説明を参照してください。

構築子と解体子

SocketNet.TcpServer.TcpServer ( int  port,
Packet  packet 
)

コンストラクタ。

引数
portバインドするポート。
packet受信するパケットの各部の長さの設定を格納するオブジェクト。

ループバックアドレスを使用します。

SocketNet.TcpServer.TcpServer ( IPAddress  ipAddress,
int  port,
Packet  packet 
)

コンストラクタ。

引数
ipAddressバインドするIPアドレス。
portバインドするポート。
packet受信するパケットの各部の長さの設定を格納するオブジェクト。

参照先 SocketNet.TcpServer.IPAddress, SocketNet.TcpServer.Port.

メソッド詳解

void SocketNet.TcpServer.CloseConnection ( TcpConnection  connection)

アクティブな接続をクローズします。

引数
connectionクローズする接続。

参照先 SocketNet.TcpConnection.Dispose().

参照元 SocketNet.TcpServer.CloseMarkedConnections(), SocketNet.TcpServer.OnDisconnected().

呼び出し関係図:

被呼び出し関係図:

void SocketNet.TcpServer.CloseMarkedConnections ( )
private

マークされた接続をクローズします。

参照先 SocketNet.TcpServer.CloseConnection().

参照元 SocketNet.TcpServer.Start().

呼び出し関係図:

被呼び出し関係図:

void SocketNet.TcpServer.Dispose ( )

オブジェクトに関連付けられたリソースを解放します。

void SocketNet.TcpServer.Dispose ( bool  disposing)
private

オブジェクトに関連付けられたリソースを解放します。

引数
disposing

参照先 SocketNet.TcpConnection.Dispose(), SocketNet.TcpServer.Stop().

呼び出し関係図:

void SocketNet.TcpServer.OnConnected ( TcpConnectionEventArgs  e)
private

接続イベントを発行します。

引数
eイベントデータを格納した TcpConnectionEventArgs オブジェクト。

参照先 SocketNet.TcpServer.Connected.

参照元 SocketNet.TcpServer.Start().

被呼び出し関係図:

void SocketNet.TcpServer.OnDataReceived ( object  sender,
TcpDataReceivedEventArgs  e 
)
private

データ受信イベントを発行します。

引数
senderセンダ。
eイベントデータを格納する TcpDataReceivedEventArgs オブジェクト。

参照先 SocketNet.TcpServer.DataReceived.

参照元 SocketNet.TcpServer.Start().

被呼び出し関係図:

void SocketNet.TcpServer.OnDisconnected ( object  sender,
TcpConnectionEventArgs  e 
)
private

切断イベントを発行します。

引数
senderセンダ。
eイベントデータを格納する TcpConnectionEventArgs オブジェクト。

参照先 SocketNet.TcpServer.CloseConnection(), SocketNet.TcpConnectionEventArgs.Connection, SocketNet.TcpServer.Disconnected.

参照元 SocketNet.TcpServer.Start().

呼び出し関係図:

被呼び出し関係図:

async Task SocketNet.TcpServer.Start ( )

TCPサーバをスタートします。

非同期で呼び出します。

戻り値
メソッドに関連付けられた Task オブジェクト。

参照先 SocketNet.TcpServer.CloseMarkedConnections(), SocketNet.TcpConnection.DataReceived, SocketNet.TcpConnection.Disconnected, SocketNet.TcpServer.IPAddress, SocketNet.TcpServer.OnConnected(), SocketNet.TcpServer.OnDataReceived(), SocketNet.TcpServer.OnDisconnected(), SocketNet.TcpServer.Port, SocketNet.TcpConnection.ReceiveDataAsync().

参照元 SampleChatServer.ChatServer.Start().

呼び出し関係図:

被呼び出し関係図:

void SocketNet.TcpServer.Stop ( )

Tcpサーバを停止します。

参照元 SocketNet.TcpServer.Dispose(), SampleChatServer.ChatServer.Stop().

被呼び出し関係図:

メンバ詳解

volatile bool SocketNet.TcpServer.acceptingConnections
private
List<TcpConnection> SocketNet.TcpServer.clientConnections
private
List<TcpConnection> SocketNet.TcpServer.connectionsToClose
private
bool SocketNet.TcpServer.disposed = false
private
volatile bool SocketNet.TcpServer.isShuttingDown
private
readonly int SocketNet.TcpServer.MaxPendingConnections = 3
static

ペンディングできる接続の最大数。

readonly Packet SocketNet.TcpServer.Packet
private
TcpListener SocketNet.TcpServer.tcpListener
private

プロパティ詳解

int SocketNet.TcpServer.ActiveConnectionCount
get

アクティブな接続の数を取得します。

ReadOnlyCollection<TcpConnection> SocketNet.TcpServer.ActiveConnections
get

アクティブな接続のリストを取得します。

IPAddress SocketNet.TcpServer.IPAddress
getprivate set

Tcpサーバにバインドされている IP アドレスを取得します。

参照元 SocketNet.TcpServer.Start(), SocketNet.TcpServer.TcpServer().

bool SocketNet.TcpServer.IsRunning
get

サーバの状態を取得します。

int SocketNet.TcpServer.Port
getprivate set

Tcpサーバにバインドされているポート番号を取得します。

参照元 SocketNet.TcpServer.Start(), SocketNet.TcpServer.TcpServer().

イベント詳解

EventHandler<TcpConnectionEventArgs> SocketNet.TcpServer.Connected

接続が確立した時に発行されます。

参照元 SampleChatServer.ChatServer.ChatServer(), SocketNet.TcpServer.OnConnected().

EventHandler<TcpDataReceivedEventArgs> SocketNet.TcpServer.DataReceived

データを受信した時に発行されます。

参照元 SampleChatServer.ChatServer.ChatServer(), SocketNet.TcpServer.OnDataReceived().

EventHandler<TcpConnectionEventArgs> SocketNet.TcpServer.Disconnected

接続が切断された時に発行されます。

参照元 SampleChatServer.ChatServer.ChatServer(), SocketNet.TcpServer.OnDisconnected().


このクラス詳解は次のファイルから抽出されました: