• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamewindowspythonphpguic翻訳omegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

ソケットを使ってクライアントサーバプログラムを作成するための C# ライブラリ


Commit MetaInfo

Révision8122e420bdbbd179d0e9aca8120640dac88b030a (tree)
l'heure2015-08-23 23:01:46
Auteurtsntsumi <tsntsumi@tsnt...>
Commitertsntsumi

Message de Log

Packet クラスの名前を PacketSpec にリファクタリング

Packet という名前と、実際に使用する際の機能が乖離していたので変更した。
実際の機能とは、パケットのヘッダ長とフッタ長とペイロード長を表すパケット
の仕様に関するものなので、PacketSpec という名前にした。

Change Summary

Modification

--- a/src/SocketNet/SampleChatClient/ChatMessage.cs
+++ b/src/SocketNet/SampleChatClient/ChatMessage.cs
@@ -33,7 +33,7 @@ namespace SampleChatClient
3333 /// <summary>
3434 /// <see cref="SampleChatServer.ChatServer"/> と <see cref="ChatClient"/> 間で送受信されるチャットメッセージを表します。
3535 /// </summary>
36- public class ChatMessage: Packet
36+ public class ChatMessage: PacketSpec
3737 {
3838 /// <summary>
3939 /// メッセージを送受信する接続を取得または設定します。
--- a/src/SocketNet/SocketNet/Packet.cs
+++ b/src/SocketNet/SocketNet/PacketSpec.cs
@@ -33,7 +33,7 @@ namespace SocketNet
3333 /// <remarks>
3434 /// 各長さを変更する場合は、このクラスから継承してプロパティ・メソッドをオーバライドします。
3535 /// </remarks>
36- public class Packet
36+ public class PacketSpec
3737 {
3838 /// <summary>
3939 /// ヘッダ長を取得します。
@@ -50,7 +50,7 @@ namespace SocketNet
5050 /// </summary>
5151 /// <param name="headerLength">ヘッダ長。</param>
5252 /// <param name="footerLength">フッタ長。</param>
53- public Packet(int headerLength = 4, int footerLength = 0)
53+ public PacketSpec(int headerLength = 4, int footerLength = 0)
5454 {
5555 HeaderLength = headerLength;
5656 FooterLength = footerLength;
--- a/src/SocketNet/SocketNet/SocketNet.csproj
+++ b/src/SocketNet/SocketNet/SocketNet.csproj
@@ -38,7 +38,6 @@
3838 <Compile Include="TcpConnectionEventArgs.cs" />
3939 <Compile Include="TcpDataReceivedEventArgs.cs" />
4040 <Compile Include="TcpServer.cs" />
41- <Compile Include="Packet.cs" />
4241 <Compile Include="UdpServer.cs" />
4342 <Compile Include="TransmissionType.cs" />
4443 <Compile Include="UdpDataReceivedEventArgs.cs" />
@@ -46,6 +45,7 @@
4645 <Compile Include="MulticastUdpServer.cs" />
4746 <Compile Include="BroadcastUdpServer.cs" />
4847 <Compile Include="LocalBroadcastUdpServer.cs" />
48+ <Compile Include="PacketSpec.cs" />
4949 </ItemGroup>
5050 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5151 </Project>
\ No newline at end of file
--- a/src/SocketNet/SocketNet/TcpConnection.cs
+++ b/src/SocketNet/SocketNet/TcpConnection.cs
@@ -64,7 +64,8 @@ namespace SocketNet
6464 public sealed class TcpConnection: IDisposable
6565 {
6666 private static readonly int ReceivedDataBufferSize = 65535;
67- private readonly Packet Packet = new Packet();
67+
68+ private readonly PacketSpec PacketSpec;
6869
6970 private object syncObject;
7071 private NetworkStream networkStream;
@@ -134,8 +135,8 @@ namespace SocketNet
134135 /// コンストラクタ。
135136 /// </summary>
136137 /// <param name="client">ソケット。</param>
137- /// <param name="packet">受信するパケットの各部の長さの設定を格納するオブジェクト。</param>
138- public TcpConnection(Socket client, Packet packet)
138+ /// <param name="packetSpec">受信するパケットの各部の長さの設定を格納するオブジェクト。</param>
139+ public TcpConnection(Socket client, PacketSpec packetSpec)
139140 {
140141 syncObject = new object();
141142 Client = client;
@@ -143,11 +144,11 @@ namespace SocketNet
143144 Reader = new BinaryReader(networkStream);
144145 Writer = new BinaryWriter(networkStream);
145146
146- Packet = packet;
147+ PacketSpec = packetSpec;
147148
148149 partiallyReceivedData = new byte[ReceivedDataBufferSize];
149150 completelyReceivedData = new List<byte>();
150- header = new byte[Packet.HeaderLength];
151+ header = new byte[PacketSpec.HeaderLength];
151152 packet = null;
152153 packetPayloadLength = 0;
153154 bytesToProcessRemaining = 0;
@@ -266,14 +267,14 @@ namespace SocketNet
266267 switch (receiveState)
267268 {
268269 case DataReceiveState.PacketHeader:
269- if (completelyReceivedData.Count >= Packet.HeaderLength)
270+ if (completelyReceivedData.Count >= PacketSpec.HeaderLength)
270271 {
271- completelyReceivedData.CopyTo(0, header, 0, Packet.HeaderLength);
272- packetPayloadLength = Packet.ObtainPayloadLength(header);
272+ completelyReceivedData.CopyTo(0, header, 0, PacketSpec.HeaderLength);
273+ packetPayloadLength = PacketSpec.ObtainPayloadLength(header);
273274
274275 receiveState = DataReceiveState.PacketPayload;
275- completelyReceivedData.RemoveRange(0, Packet.HeaderLength);
276- bytesToProcessRemaining -= Packet.HeaderLength;
276+ completelyReceivedData.RemoveRange(0, PacketSpec.HeaderLength);
277+ bytesToProcessRemaining -= PacketSpec.HeaderLength;
277278 }
278279 else
279280 {
@@ -284,15 +285,15 @@ namespace SocketNet
284285 case DataReceiveState.PacketPayload:
285286 if (completelyReceivedData.Count >= packetPayloadLength)
286287 {
287- packet = new byte[Packet.HeaderLength + packetPayloadLength + Packet.FooterLength];
288- Array.Copy(header, packet, Packet.HeaderLength);
289- completelyReceivedData.CopyTo(0, packet, Packet.HeaderLength, packetPayloadLength);
288+ packet = new byte[PacketSpec.HeaderLength + packetPayloadLength + PacketSpec.FooterLength];
289+ Array.Copy(header, packet, PacketSpec.HeaderLength);
290+ completelyReceivedData.CopyTo(0, packet, PacketSpec.HeaderLength, packetPayloadLength);
290291
291292 receiveState = DataReceiveState.PacketFooter;
292293 completelyReceivedData.RemoveRange(0, packetPayloadLength);
293294 bytesToProcessRemaining -= packetPayloadLength;
294295
295- if (Packet.FooterLength == 0)
296+ if (PacketSpec.FooterLength == 0)
296297 {
297298 OnDataReceived(new TcpDataReceivedEventArgs(this, packet));
298299 receiveState = DataReceiveState.PacketHeader;
@@ -305,15 +306,15 @@ namespace SocketNet
305306 break;
306307
307308 case DataReceiveState.PacketFooter:
308- if (completelyReceivedData.Count >= Packet.FooterLength)
309+ if (completelyReceivedData.Count >= PacketSpec.FooterLength)
309310 {
310- completelyReceivedData.CopyTo(0, packet, Packet.HeaderLength + packetPayloadLength, Packet.FooterLength);
311+ completelyReceivedData.CopyTo(0, packet, PacketSpec.HeaderLength + packetPayloadLength, PacketSpec.FooterLength);
311312
312313 OnDataReceived(new TcpDataReceivedEventArgs(this, packet));
313314
314315 receiveState = DataReceiveState.PacketHeader;
315- completelyReceivedData.RemoveRange(0, Packet.FooterLength);
316- bytesToProcessRemaining -= Packet.FooterLength;
316+ completelyReceivedData.RemoveRange(0, PacketSpec.FooterLength);
317+ bytesToProcessRemaining -= PacketSpec.FooterLength;
317318 }
318319 else
319320 {
--- a/src/SocketNet/SocketNet/TcpServer.cs
+++ b/src/SocketNet/SocketNet/TcpServer.cs
@@ -59,7 +59,7 @@ namespace SocketNet
5959 /// </summary>
6060 public static readonly int MaxPendingConnections = 3;
6161
62- private readonly Packet Packet;
62+ private readonly PacketSpec PacketSpec;
6363
6464 private TcpListener tcpListener;
6565 private List<TcpConnection> clientConnections;
@@ -138,7 +138,7 @@ namespace SocketNet
138138 /// <remarks>
139139 /// ループバックアドレスを使用します。
140140 /// </remarks>
141- public TcpServer(int port, Packet packet)
141+ public TcpServer(int port, PacketSpec packet)
142142 : this(IPAddress.Loopback, port, packet)
143143 {
144144 }
@@ -148,12 +148,12 @@ namespace SocketNet
148148 /// </summary>
149149 /// <param name="ipAddress">バインドするIPアドレス。</param>
150150 /// <param name="port">バインドするポート。</param>
151- /// <param name="packet">受信するパケットの各部の長さの設定を格納するオブジェクト。</param>
152- public TcpServer(IPAddress ipAddress, int port, Packet packet)
151+ /// <param name="packetSpec">受信するパケットの各部の長さの設定を格納するオブジェクト。</param>
152+ public TcpServer(IPAddress ipAddress, int port, PacketSpec packetSpec)
153153 {
154154 IPAddress = ipAddress;
155155 Port = port;
156- Packet = packet;
156+ PacketSpec = packetSpec;
157157 clientConnections = new List<TcpConnection>();
158158 connectionsToClose = new List<TcpConnection>();
159159 isShuttingDown = false;
@@ -237,7 +237,7 @@ namespace SocketNet
237237
238238 await Task.Run(() =>
239239 {
240- TcpConnection connection = new TcpConnection(socket, Packet);
240+ TcpConnection connection = new TcpConnection(socket, PacketSpec);
241241 connection.Disconnected += new EventHandler<TcpConnectionEventArgs>(OnDisconnected);
242242 connection.DataReceived += new EventHandler<TcpDataReceivedEventArgs>(OnDataReceived);
243243