I_Jemin

New Proejct: Basic Network Library

Add PacketQeue for fluent packet stacking
Showing 319 changed files with 543 additions and 0 deletions
...@@ -8,6 +8,16 @@ ...@@ -8,6 +8,16 @@
8 # Visual Studio 2015 cache directory 8 # Visual Studio 2015 cache directory
9 /Basic Socket Programming/.vs/ 9 /Basic Socket Programming/.vs/
10 10
11 +/Basic Network Library/[Ll]ibrary/
12 +/Basic Network Library/[Tt]emp/
13 +/Basic Network Library/[Oo]bj/
14 +/Basic Network Library/[Bb]uild/
15 +/Basic Network Library/[Bb]uilds/
16 +/Basic Network Library/Assets/AssetStoreTools*
17 +
18 +# Visual Studio 2015 cache directory
19 +/Basic Network Library/.vs/
20 +
11 # Autogenerated VS/MD/Consulo solution and project files 21 # Autogenerated VS/MD/Consulo solution and project files
12 ExportedObj/ 22 ExportedObj/
13 .consulo/ 23 .consulo/
......
1 +{
2 + "files.exclude":
3 + {
4 + "**/.DS_Store":true,
5 + "**/.git":true,
6 + "**/.gitignore":true,
7 + "**/.gitmodules":true,
8 + "**/*.booproj":true,
9 + "**/*.pidb":true,
10 + "**/*.suo":true,
11 + "**/*.user":true,
12 + "**/*.userprefs":true,
13 + "**/*.unityproj":true,
14 + "**/*.dll":true,
15 + "**/*.exe":true,
16 + "**/*.pdf":true,
17 + "**/*.mid":true,
18 + "**/*.midi":true,
19 + "**/*.wav":true,
20 + "**/*.gif":true,
21 + "**/*.ico":true,
22 + "**/*.jpg":true,
23 + "**/*.jpeg":true,
24 + "**/*.png":true,
25 + "**/*.psd":true,
26 + "**/*.tga":true,
27 + "**/*.tif":true,
28 + "**/*.tiff":true,
29 + "**/*.3ds":true,
30 + "**/*.3DS":true,
31 + "**/*.fbx":true,
32 + "**/*.FBX":true,
33 + "**/*.lxo":true,
34 + "**/*.LXO":true,
35 + "**/*.ma":true,
36 + "**/*.MA":true,
37 + "**/*.obj":true,
38 + "**/*.OBJ":true,
39 + "**/*.asset":true,
40 + "**/*.cubemap":true,
41 + "**/*.flare":true,
42 + "**/*.mat":true,
43 + "**/*.meta":true,
44 + "**/*.prefab":true,
45 + "**/*.unity":true,
46 + "build/":true,
47 + "Build/":true,
48 + "Library/":true,
49 + "library/":true,
50 + "obj/":true,
51 + "Obj/":true,
52 + "ProjectSettings/":true,
53 + "temp/":true,
54 + "Temp/":true
55 + }
56 +}
...\ No newline at end of file ...\ No newline at end of file
1 +%YAML 1.1
2 +%TAG !u! tag:unity3d.com,2011:
3 +--- !u!29 &1
4 +OcclusionCullingSettings:
5 + m_ObjectHideFlags: 0
6 + serializedVersion: 2
7 + m_OcclusionBakeSettings:
8 + smallestOccluder: 5
9 + smallestHole: 0.25
10 + backfaceThreshold: 100
11 + m_SceneGUID: 00000000000000000000000000000000
12 + m_OcclusionCullingData: {fileID: 0}
13 +--- !u!104 &2
14 +RenderSettings:
15 + m_ObjectHideFlags: 0
16 + serializedVersion: 8
17 + m_Fog: 0
18 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
19 + m_FogMode: 3
20 + m_FogDensity: 0.01
21 + m_LinearFogStart: 0
22 + m_LinearFogEnd: 300
23 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
24 + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
25 + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
26 + m_AmbientIntensity: 1
27 + m_AmbientMode: 0
28 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
29 + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
30 + m_HaloStrength: 0.5
31 + m_FlareStrength: 1
32 + m_FlareFadeSpeed: 3
33 + m_HaloTexture: {fileID: 0}
34 + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
35 + m_DefaultReflectionMode: 0
36 + m_DefaultReflectionResolution: 128
37 + m_ReflectionBounces: 1
38 + m_ReflectionIntensity: 1
39 + m_CustomReflection: {fileID: 0}
40 + m_Sun: {fileID: 0}
41 + m_IndirectSpecularColor: {r: 0.4465934, g: 0.49642956, b: 0.57482487, a: 1}
42 +--- !u!157 &3
43 +LightmapSettings:
44 + m_ObjectHideFlags: 0
45 + serializedVersion: 11
46 + m_GIWorkflowMode: 0
47 + m_GISettings:
48 + serializedVersion: 2
49 + m_BounceScale: 1
50 + m_IndirectOutputScale: 1
51 + m_AlbedoBoost: 1
52 + m_TemporalCoherenceThreshold: 1
53 + m_EnvironmentLightingMode: 0
54 + m_EnableBakedLightmaps: 1
55 + m_EnableRealtimeLightmaps: 1
56 + m_LightmapEditorSettings:
57 + serializedVersion: 9
58 + m_Resolution: 2
59 + m_BakeResolution: 40
60 + m_TextureWidth: 1024
61 + m_TextureHeight: 1024
62 + m_AO: 0
63 + m_AOMaxDistance: 1
64 + m_CompAOExponent: 1
65 + m_CompAOExponentDirect: 0
66 + m_Padding: 2
67 + m_LightmapParameters: {fileID: 0}
68 + m_LightmapsBakeMode: 1
69 + m_TextureCompression: 1
70 + m_FinalGather: 0
71 + m_FinalGatherFiltering: 1
72 + m_FinalGatherRayCount: 256
73 + m_ReflectionCompression: 2
74 + m_MixedBakeMode: 2
75 + m_BakeBackend: 0
76 + m_PVRSampling: 1
77 + m_PVRDirectSampleCount: 32
78 + m_PVRSampleCount: 500
79 + m_PVRBounces: 2
80 + m_PVRFilterTypeDirect: 0
81 + m_PVRFilterTypeIndirect: 0
82 + m_PVRFilterTypeAO: 0
83 + m_PVRFilteringMode: 1
84 + m_PVRCulling: 1
85 + m_PVRFilteringGaussRadiusDirect: 1
86 + m_PVRFilteringGaussRadiusIndirect: 5
87 + m_PVRFilteringGaussRadiusAO: 2
88 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5
89 + m_PVRFilteringAtrousPositionSigmaIndirect: 2
90 + m_PVRFilteringAtrousPositionSigmaAO: 1
91 + m_ShowResolutionOverlay: 1
92 + m_LightingDataAsset: {fileID: 0}
93 + m_UseShadowmask: 1
94 +--- !u!196 &4
95 +NavMeshSettings:
96 + serializedVersion: 2
97 + m_ObjectHideFlags: 0
98 + m_BuildSettings:
99 + serializedVersion: 2
100 + agentTypeID: 0
101 + agentRadius: 0.5
102 + agentHeight: 2
103 + agentSlope: 45
104 + agentClimb: 0.4
105 + ledgeDropHeight: 0
106 + maxJumpAcrossDistance: 0
107 + minRegionArea: 2
108 + manualCellSize: 0
109 + cellSize: 0.16666667
110 + manualTileSize: 0
111 + tileSize: 256
112 + accuratePlacement: 0
113 + debug:
114 + m_Flags: 0
115 + m_NavMeshData: {fileID: 0}
116 +--- !u!1 &80931628
117 +GameObject:
118 + m_ObjectHideFlags: 0
119 + m_PrefabParentObject: {fileID: 0}
120 + m_PrefabInternal: {fileID: 0}
121 + serializedVersion: 5
122 + m_Component:
123 + - component: {fileID: 80931630}
124 + - component: {fileID: 80931629}
125 + m_Layer: 0
126 + m_Name: Directional Light
127 + m_TagString: Untagged
128 + m_Icon: {fileID: 0}
129 + m_NavMeshLayer: 0
130 + m_StaticEditorFlags: 0
131 + m_IsActive: 1
132 +--- !u!108 &80931629
133 +Light:
134 + m_ObjectHideFlags: 0
135 + m_PrefabParentObject: {fileID: 0}
136 + m_PrefabInternal: {fileID: 0}
137 + m_GameObject: {fileID: 80931628}
138 + m_Enabled: 1
139 + serializedVersion: 8
140 + m_Type: 1
141 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
142 + m_Intensity: 1
143 + m_Range: 10
144 + m_SpotAngle: 30
145 + m_CookieSize: 10
146 + m_Shadows:
147 + m_Type: 2
148 + m_Resolution: -1
149 + m_CustomResolution: -1
150 + m_Strength: 1
151 + m_Bias: 0.05
152 + m_NormalBias: 0.4
153 + m_NearPlane: 0.2
154 + m_Cookie: {fileID: 0}
155 + m_DrawHalo: 0
156 + m_Flare: {fileID: 0}
157 + m_RenderMode: 0
158 + m_CullingMask:
159 + serializedVersion: 2
160 + m_Bits: 4294967295
161 + m_Lightmapping: 4
162 + m_AreaSize: {x: 1, y: 1}
163 + m_BounceIntensity: 1
164 + m_ColorTemperature: 6570
165 + m_UseColorTemperature: 0
166 + m_ShadowRadius: 0
167 + m_ShadowAngle: 0
168 +--- !u!4 &80931630
169 +Transform:
170 + m_ObjectHideFlags: 0
171 + m_PrefabParentObject: {fileID: 0}
172 + m_PrefabInternal: {fileID: 0}
173 + m_GameObject: {fileID: 80931628}
174 + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
175 + m_LocalPosition: {x: 0, y: 3, z: 0}
176 + m_LocalScale: {x: 1, y: 1, z: 1}
177 + m_Children: []
178 + m_Father: {fileID: 0}
179 + m_RootOrder: 1
180 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
181 +--- !u!1 &457575255
182 +GameObject:
183 + m_ObjectHideFlags: 0
184 + m_PrefabParentObject: {fileID: 0}
185 + m_PrefabInternal: {fileID: 0}
186 + serializedVersion: 5
187 + m_Component:
188 + - component: {fileID: 457575259}
189 + - component: {fileID: 457575258}
190 + - component: {fileID: 457575257}
191 + - component: {fileID: 457575256}
192 + m_Layer: 0
193 + m_Name: Main Camera
194 + m_TagString: MainCamera
195 + m_Icon: {fileID: 0}
196 + m_NavMeshLayer: 0
197 + m_StaticEditorFlags: 0
198 + m_IsActive: 1
199 +--- !u!81 &457575256
200 +AudioListener:
201 + m_ObjectHideFlags: 0
202 + m_PrefabParentObject: {fileID: 0}
203 + m_PrefabInternal: {fileID: 0}
204 + m_GameObject: {fileID: 457575255}
205 + m_Enabled: 1
206 +--- !u!124 &457575257
207 +Behaviour:
208 + m_ObjectHideFlags: 0
209 + m_PrefabParentObject: {fileID: 0}
210 + m_PrefabInternal: {fileID: 0}
211 + m_GameObject: {fileID: 457575255}
212 + m_Enabled: 1
213 +--- !u!20 &457575258
214 +Camera:
215 + m_ObjectHideFlags: 0
216 + m_PrefabParentObject: {fileID: 0}
217 + m_PrefabInternal: {fileID: 0}
218 + m_GameObject: {fileID: 457575255}
219 + m_Enabled: 1
220 + serializedVersion: 2
221 + m_ClearFlags: 1
222 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
223 + m_NormalizedViewPortRect:
224 + serializedVersion: 2
225 + x: 0
226 + y: 0
227 + width: 1
228 + height: 1
229 + near clip plane: 0.3
230 + far clip plane: 1000
231 + field of view: 60
232 + orthographic: 0
233 + orthographic size: 5
234 + m_Depth: -1
235 + m_CullingMask:
236 + serializedVersion: 2
237 + m_Bits: 4294967295
238 + m_RenderingPath: -1
239 + m_TargetTexture: {fileID: 0}
240 + m_TargetDisplay: 0
241 + m_TargetEye: 3
242 + m_HDR: 1
243 + m_AllowMSAA: 1
244 + m_AllowDynamicResolution: 0
245 + m_ForceIntoRT: 0
246 + m_OcclusionCulling: 1
247 + m_StereoConvergence: 10
248 + m_StereoSeparation: 0.022
249 +--- !u!4 &457575259
250 +Transform:
251 + m_ObjectHideFlags: 0
252 + m_PrefabParentObject: {fileID: 0}
253 + m_PrefabInternal: {fileID: 0}
254 + m_GameObject: {fileID: 457575255}
255 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
256 + m_LocalPosition: {x: 0, y: 1, z: -10}
257 + m_LocalScale: {x: 1, y: 1, z: 1}
258 + m_Children: []
259 + m_Father: {fileID: 0}
260 + m_RootOrder: 0
261 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1 +fileFormatVersion: 2
2 +guid: 0964de8e148954ac9b3ff232fe86b110
3 +timeCreated: 1517148581
4 +licenseType: Pro
5 +DefaultImporter:
6 + externalObjects: {}
7 + userData:
8 + assetBundleName:
9 + assetBundleVariant:
1 +fileFormatVersion: 2
2 +guid: c9304ab32d5a14ac0bb8f406e2082281
3 +folderAsset: yes
4 +timeCreated: 1517148587
5 +licenseType: Pro
6 +DefaultImporter:
7 + externalObjects: {}
8 + userData:
9 + assetBundleName:
10 + assetBundleVariant:
1 +using System;
2 +using System.Collections;
3 +using System.Collections.Generic;
4 +using System.IO;
5 +using System.Runtime.InteropServices; // https://msdn.microsoft.com/ko-kr/library/system.runtime.interopservices(v=vs.110).aspx
6 +
7 +// 이 타입의 목적: 물흐르듯이 패킷을 쌓고 꺼내올수 있는 큐
8 +public class PacketQueue
9 +{
10 + // 대응되는 패킷이 정확히 스트림에서 어디 인덱스에 존재하는지 지정
11 + struct PacketInfo
12 + {
13 + public int offset; // 이 데이터가 기록되기 시작한 지점
14 + public int size; // 이 데이터의 사이즈
15 + }
16 +
17 + // MemoryStream 은 데이터를 연속적으로 쌓고 빼낼수 있는 스트림 버퍼
18 + // MemoryStream 은 디스크나 네트워크 연결이 아니라 메모리 상에 데이터를 저장하는 스트림 버퍼
19 + // 데이터의 끊김이 없으므로 패킷으로는 다룰수 없다
20 + private MemoryStream m_streamBuffer;
21 +
22 +
23 + private List<PacketInfo> m_waitingPackets; // 아직 디큐하지 못하고 쌓인 패킷들
24 +
25 + private int m_cursor = 0; // 버퍼가 채워져 커서가 밀려난 지점, 데이터를 채울때 여기서 부터 채우면 됨
26 +
27 + private Object lockObj = new Object(); // 데드락 방지용 단순 참고자
28 +
29 + // 초기화
30 + public PacketQueue()
31 + {
32 + m_streamBuffer = new MemoryStream();
33 + m_waitingPackets = new List<PacketInfo>();
34 + }
35 +
36 + // 큐에 바이트 데이터 추가
37 + public int Enqueue(byte[] data, int size)
38 + {
39 + PacketInfo info = new PacketInfo();
40 +
41 + info.offset = m_cursor; // 스트림내에서 이 데이터를 찾으려면 어디서 부터 읽으면 되는지 기록
42 + info.size = size;
43 +
44 + lock(lockObj) // 데드락 방지
45 + {
46 + // 패킷 저장 정보를 보존
47 + m_waitingPackets.Add(info);
48 +
49 + // 패킷 데이터를 추가
50 +
51 + m_streamBuffer.Position = m_cursor; // 스트림의 위치를 마지막으로 갱신한 커서 위치로.
52 + m_streamBuffer.Write(data,0,size); // 현재 위치에서 사이즈만큼 버퍼를 쌓기
53 + m_streamBuffer.Flush(); // 적용
54 +
55 + m_cursor += size; // 커서를 방금 추가한 패킷 만큼 오른쪽으로 이동
56 + }
57 +
58 + return size; // 추가된 데이터의 사이즈를 리턴
59 + }
60 +
61 + // 버퍼를 맡기면 채워서 넘겨줌
62 + public int Dequeue(ref byte[] buffer, int size)
63 + {
64 + // 패킷 리스트에 남아있는게 없다면 종료
65 + if(m_waitingPackets.Count <= 0)
66 + {
67 + return -1;
68 + }
69 +
70 + int recvSize = 0;
71 +
72 + // 데드락 방지
73 + lock(lockObj) {
74 + // 가장 마지막에 추가된 패킷부터 가져온다
75 + PacketInfo info = m_waitingPackets[0];
76 +
77 + // 저장된 패킷 이상의 사이즈를 긁어올순 없음
78 + int dataSize = Math.Min(size, info.size);
79 +
80 + // 읽기 시작할 위치
81 + m_streamBuffer.Position = info.offset;
82 + // 현재 커서 위치에서 dataSize 만큼 오른쪽만큼 이동한 지점까지를 영역으로
83 + // 데이터를 긁어와 입력으로 들어온 buffer 를 채움
84 + recvSize = m_streamBuffer.Read(buffer, 0, dataSize);
85 +
86 + // 패킷을 꺼냈으므로 꺼낸 패킷에 대한 패킷 기록을 리스트에서 삭제
87 + if(recvSize > 0)
88 + {
89 + m_waitingPackets.RemoveAt(0);
90 + }
91 +
92 + // 모든 큐 데이터를 꺼냈을때는 스트림을 다시 제로포인트로 클리어해서 메모리를 절약
93 + if(m_waitingPackets.Count == 0)
94 + {
95 + Clear();
96 + m_cursor = 0;
97 + }
98 +
99 + }
100 + return recvSize;
101 +
102 + }
103 +
104 + // 스트림버퍼의 커서를 초기화. 큐와 메모리 클리어
105 + public void Clear()
106 + {
107 + // 스트림 버퍼의 남은 데이터를 긁어서
108 + byte[] buffer = m_streamBuffer.GetBuffer();
109 + // 해당 데이터를 정렬함
110 + Array.Clear(buffer,0,buffer.Length);
111 +
112 + // 스트림 버퍼의 커서와 길이를 제로로 되돌리기
113 + m_streamBuffer.Position = 0;
114 + m_streamBuffer.SetLength(0);
115 + }
116 +
117 +}
...\ No newline at end of file ...\ No newline at end of file
1 +fileFormatVersion: 2
2 +guid: 6f23052345bf649c485f9d14c8d027ae
3 +timeCreated: 1517148877
4 +licenseType: Pro
5 +MonoImporter:
6 + externalObjects: {}
7 + serializedVersion: 2
8 + defaultReferences: []
9 + executionOrder: 0
10 + icon: {instanceID: 0}
11 + userData:
12 + assetBundleName:
13 + assetBundleVariant:
1 +using UnityEngine;
2 +using System.Collections;
3 +using System.Net;
4 +using System.Net.Sockets;
5 +using System.Threading;
6 +
7 +
8 +public class TransportTCP : MonoBehaviour {
9 +
10 + // 소켓 액세스
11 +
12 + // 리스너 소켓
13 + private Socket m_listener = null;
14 +
15 +
16 +
17 +
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +fileFormatVersion: 2
2 +guid: cd5fc2b6c1dde473792533471913965f
3 +timeCreated: 1517148595
4 +licenseType: Pro
5 +MonoImporter:
6 + externalObjects: {}
7 + serializedVersion: 2
8 + defaultReferences: []
9 + executionOrder: 0
10 + icon: {instanceID: 0}
11 + userData:
12 + assetBundleName:
13 + assetBundleVariant:
1 +using System.Collections;
2 +using System.Collections.Generic;
3 +using UnityEngine;
4 +using System.Net;
5 +using System.Net.Sockets;
6 +
7 +public class TransportUDP : MonoBehaviour {
8 +
9 + // 소켓 액세스 포인트들
10 +
11 + // 클라이언트의 접속을 받을 소켓
12 + private Socket m_socket = null;
13 +}
1 +fileFormatVersion: 2
2 +guid: a9312813559bd41e9b935e2418917ad0
3 +timeCreated: 1517148687
4 +licenseType: Pro
5 +MonoImporter:
6 + externalObjects: {}
7 + serializedVersion: 2
8 + defaultReferences: []
9 + executionOrder: 0
10 + icon: {instanceID: 0}
11 + userData:
12 + assetBundleName:
13 + assetBundleVariant:
1 +2;0;196608;0;0
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +{
2 + "process_id" : 2262,
3 + "version" : "2017.3.0p3"
4 +}
...\ No newline at end of file ...\ No newline at end of file
1 +unityRebuildLibraryVersion: 11
2 +unityForwardCompatibleVersion: 40
This diff is collapsed. Click to expand it.
1 +0000.5a5ca137.0000
2 +0000.5a5ca0f8.0000
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.