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 @@
# Visual Studio 2015 cache directory
/Basic Socket Programming/.vs/
/Basic Network Library/[Ll]ibrary/
/Basic Network Library/[Tt]emp/
/Basic Network Library/[Oo]bj/
/Basic Network Library/[Bb]uild/
/Basic Network Library/[Bb]uilds/
/Basic Network Library/Assets/AssetStoreTools*
# Visual Studio 2015 cache directory
/Basic Network Library/.vs/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
......
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitignore":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
\ No newline at end of file
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4465934, g: 0.49642956, b: 0.57482487, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &80931628
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 80931630}
- component: {fileID: 80931629}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &80931629
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 80931628}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &80931630
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 80931628}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &457575255
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 457575259}
- component: {fileID: 457575258}
- component: {fileID: 457575257}
- component: {fileID: 457575256}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &457575256
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 457575255}
m_Enabled: 1
--- !u!124 &457575257
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 457575255}
m_Enabled: 1
--- !u!20 &457575258
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 457575255}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &457575259
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 457575255}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
fileFormatVersion: 2
guid: 0964de8e148954ac9b3ff232fe86b110
timeCreated: 1517148581
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c9304ab32d5a14ac0bb8f406e2082281
folderAsset: yes
timeCreated: 1517148587
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices; // https://msdn.microsoft.com/ko-kr/library/system.runtime.interopservices(v=vs.110).aspx
// 이 타입의 목적: 물흐르듯이 패킷을 쌓고 꺼내올수 있는 큐
public class PacketQueue
{
// 대응되는 패킷이 정확히 스트림에서 어디 인덱스에 존재하는지 지정
struct PacketInfo
{
public int offset; // 이 데이터가 기록되기 시작한 지점
public int size; // 이 데이터의 사이즈
}
// MemoryStream 은 데이터를 연속적으로 쌓고 빼낼수 있는 스트림 버퍼
// MemoryStream 은 디스크나 네트워크 연결이 아니라 메모리 상에 데이터를 저장하는 스트림 버퍼
// 데이터의 끊김이 없으므로 패킷으로는 다룰수 없다
private MemoryStream m_streamBuffer;
private List<PacketInfo> m_waitingPackets; // 아직 디큐하지 못하고 쌓인 패킷들
private int m_cursor = 0; // 버퍼가 채워져 커서가 밀려난 지점, 데이터를 채울때 여기서 부터 채우면 됨
private Object lockObj = new Object(); // 데드락 방지용 단순 참고자
// 초기화
public PacketQueue()
{
m_streamBuffer = new MemoryStream();
m_waitingPackets = new List<PacketInfo>();
}
// 큐에 바이트 데이터 추가
public int Enqueue(byte[] data, int size)
{
PacketInfo info = new PacketInfo();
info.offset = m_cursor; // 스트림내에서 이 데이터를 찾으려면 어디서 부터 읽으면 되는지 기록
info.size = size;
lock(lockObj) // 데드락 방지
{
// 패킷 저장 정보를 보존
m_waitingPackets.Add(info);
// 패킷 데이터를 추가
m_streamBuffer.Position = m_cursor; // 스트림의 위치를 마지막으로 갱신한 커서 위치로.
m_streamBuffer.Write(data,0,size); // 현재 위치에서 사이즈만큼 버퍼를 쌓기
m_streamBuffer.Flush(); // 적용
m_cursor += size; // 커서를 방금 추가한 패킷 만큼 오른쪽으로 이동
}
return size; // 추가된 데이터의 사이즈를 리턴
}
// 버퍼를 맡기면 채워서 넘겨줌
public int Dequeue(ref byte[] buffer, int size)
{
// 패킷 리스트에 남아있는게 없다면 종료
if(m_waitingPackets.Count <= 0)
{
return -1;
}
int recvSize = 0;
// 데드락 방지
lock(lockObj) {
// 가장 마지막에 추가된 패킷부터 가져온다
PacketInfo info = m_waitingPackets[0];
// 저장된 패킷 이상의 사이즈를 긁어올순 없음
int dataSize = Math.Min(size, info.size);
// 읽기 시작할 위치
m_streamBuffer.Position = info.offset;
// 현재 커서 위치에서 dataSize 만큼 오른쪽만큼 이동한 지점까지를 영역으로
// 데이터를 긁어와 입력으로 들어온 buffer 를 채움
recvSize = m_streamBuffer.Read(buffer, 0, dataSize);
// 패킷을 꺼냈으므로 꺼낸 패킷에 대한 패킷 기록을 리스트에서 삭제
if(recvSize > 0)
{
m_waitingPackets.RemoveAt(0);
}
// 모든 큐 데이터를 꺼냈을때는 스트림을 다시 제로포인트로 클리어해서 메모리를 절약
if(m_waitingPackets.Count == 0)
{
Clear();
m_cursor = 0;
}
}
return recvSize;
}
// 스트림버퍼의 커서를 초기화. 큐와 메모리 클리어
public void Clear()
{
// 스트림 버퍼의 남은 데이터를 긁어서
byte[] buffer = m_streamBuffer.GetBuffer();
// 해당 데이터를 정렬함
Array.Clear(buffer,0,buffer.Length);
// 스트림 버퍼의 커서와 길이를 제로로 되돌리기
m_streamBuffer.Position = 0;
m_streamBuffer.SetLength(0);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6f23052345bf649c485f9d14c8d027ae
timeCreated: 1517148877
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Threading;
public class TransportTCP : MonoBehaviour {
// 소켓 액세스
// 리스너 소켓
private Socket m_listener = null;
}
\ No newline at end of file
fileFormatVersion: 2
guid: cd5fc2b6c1dde473792533471913965f
timeCreated: 1517148595
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.Net.Sockets;
public class TransportUDP : MonoBehaviour {
// 소켓 액세스 포인트들
// 클라이언트의 접속을 받을 소켓
private Socket m_socket = null;
}
fileFormatVersion: 2
guid: a9312813559bd41e9b935e2418917ad0
timeCreated: 1517148687
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
2;0;196608;0;0
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"process_id" : 2262,
"version" : "2017.3.0p3"
}
\ No newline at end of file
unityRebuildLibraryVersion: 11
unityForwardCompatibleVersion: 40
This diff is collapsed. Click to expand it.
0000.5a5ca137.0000
0000.5a5ca0f8.0000
\ 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.