Toggle navigation
Toggle navigation
This project
Loading...
Sign in
I_Jemin
/
dotnet-Network-Programming-with-Unity
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
I_Jemin
2018-01-29 02:08:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a5736f1f6b1aa4b0e09675766f91d65ae612d148
a5736f1f
1 parent
858a1b68
Add demo script
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
163 additions
and
17 deletions
Basic Network Library/Assets/Scripts/LibrarySample.cs
Basic Network Library/Assets/Scripts/LibrarySample.cs.meta
Basic Network Library/Library/CurrentLayout.dwlt
Basic Network Library/Library/ScriptAssemblies/Assembly-CSharp.dll
Basic Network Library/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb
Basic Network Library/Library/assetDatabase3
Basic Network Library/obj/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache
Basic Network Library/Assets/Scripts/LibrarySample.cs
0 → 100644
View file @
a5736f1
// TCP로 통신할 때는 정의를 유효하게 하여 주십시오.
#define USE_TRANSPORT_TCP
using
UnityEngine
;
using
System.Collections
;
using
System.Net
;
public
class
LibrarySample
:
MonoBehaviour
{
// 통신 모듈.
public
GameObject
transportTcpPrefab
;
public
GameObject
transportUdpPrefab
;
// 통신용 변수.
#if USE_TRANSPORT_TCP
TransportTCP
m_transport
=
null
;
#else
TransportUDP
m_transport
=
null
;
#endif
// 접속할 IP 주소.
private
string
m_strings
=
""
;
// 접속할 포트 번호.
private
const
int
m_port
=
50765
;
private
const
int
m_mtu
=
1400
;
private
bool
isSelected
=
false
;
// Use this for initialization
void
Start
()
{
// Transport 클래스의 컴포넌트를 가져온다.
#if USE_TRANSPORT_TCP
GameObject
obj
=
GameObject
.
Instantiate
(
transportTcpPrefab
)
as
GameObject
;
m_transport
=
obj
.
GetComponent
<
TransportTCP
>();
#else
GameObject
obj
=
GameObject
.
Instantiate
(
transportUdpPrefab
)
as
GameObject
;
m_transport
=
obj
.
GetComponent
<
TransportUDP
>();
#endif
IPHostEntry
hostEntry
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
System
.
Net
.
IPAddress
hostAddress
=
hostEntry
.
AddressList
[
0
];
Debug
.
Log
(
hostEntry
.
HostName
);
m_strings
=
hostAddress
.
ToString
();
}
// Update is called once per frame
void
Update
()
{
if
(
m_transport
!=
null
&&
m_transport
.
isConnected
==
true
)
{
byte
[]
buffer
=
new
byte
[
m_mtu
];
int
recvSize
=
m_transport
.
Receive
(
ref
buffer
,
buffer
.
Length
);
if
(
recvSize
>
0
)
{
string
message
=
System
.
Text
.
Encoding
.
UTF8
.
GetString
(
buffer
);
Debug
.
Log
(
message
);
}
}
}
void
OnGUI
()
{
if
(
isSelected
==
false
)
{
OnGUISelectHost
();
}
else
{
if
(
m_transport
.
isServer
==
true
)
{
OnGUIServer
();
}
else
{
OnGUIClient
();
}
}
}
void
OnGUISelectHost
()
{
#if USE_TRANSPORT_TCP
if
(
GUI
.
Button
(
new
Rect
(
20
,
40
,
150
,
20
),
"Launch server."
))
{
#else
if
(
GUI
.
Button
(
new
Rect
(
20
,
40
,
150
,
20
),
"Launch Listener."
))
{
#endif
m_transport
.
StartServer
(
m_port
,
1
);
isSelected
=
true
;
}
// 클라이언트를 선택했을 때 접속할 서버 주소를 입력합니다.
m_strings
=
GUI
.
TextField
(
new
Rect
(
20
,
100
,
200
,
20
),
m_strings
);
#if USE_TRANSPORT_TCP
if
(
GUI
.
Button
(
new
Rect
(
20
,
70
,
150
,
20
),
"Connect to server"
))
{
#else
if
(
GUI
.
Button
(
new
Rect
(
20
,
70
,
150
,
20
),
"Connect to terminal"
))
{
#endif
m_transport
.
Connect
(
m_strings
,
m_port
);
isSelected
=
true
;
m_strings
=
""
;
}
}
void
OnGUIServer
()
{
#if USE_TRANSPORT_TCP
if
(
GUI
.
Button
(
new
Rect
(
20
,
60
,
150
,
20
),
"Stop server"
))
{
#else
if
(
GUI
.
Button
(
new
Rect
(
20
,
60
,
150
,
20
),
"Stop Listener"
))
{
#endif
m_transport
.
StopServer
();
isSelected
=
false
;
m_strings
=
""
;
}
}
void
OnGUIClient
()
{
// 클라이언트를 선택했을 때 접속할 서버의 주소를 입력합니다.
if
(
GUI
.
Button
(
new
Rect
(
20
,
70
,
150
,
20
),
"Send message"
))
{
byte
[]
buffer
=
System
.
Text
.
Encoding
.
UTF8
.
GetBytes
(
"Hellow, this is client."
);
m_transport
.
Send
(
buffer
,
buffer
.
Length
);
}
if
(
GUI
.
Button
(
new
Rect
(
20
,
100
,
150
,
20
),
"Disconnect"
))
{
m_transport
.
Disconnect
();
isSelected
=
false
;
m_strings
=
""
;
}
}
}
\ No newline at end of file
Basic Network Library/Assets/Scripts/LibrarySample.cs.meta
0 → 100644
View file @
a5736f1
fileFormatVersion: 2
guid: aa61c0cf4489b43888605561c5b33086
timeCreated: 1517159051
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Basic Network Library/Library/CurrentLayout.dwlt
View file @
a5736f1
...
...
@@ -20,7 +20,7 @@ MonoBehaviour:
m_ShowMode
:
4
m_Title
:
m_RootView
:
{
fileID
:
6
}
m_MinSize
:
{
x
:
950
,
y
:
300
}
m_MinSize
:
{
x
:
950
,
y
:
521
}
m_MaxSize
:
{
x
:
10000
,
y
:
10000
}
---
!u!114
&2
MonoBehaviour
:
...
...
@@ -40,8 +40,8 @@ MonoBehaviour:
y
:
657
width
:
567
height
:
328
m_MinSize
:
{
x
:
10
2
,
y
:
121
}
m_MaxSize
:
{
x
:
400
2
,
y
:
4021
}
m_MinSize
:
{
x
:
10
0
,
y
:
100
}
m_MaxSize
:
{
x
:
400
0
,
y
:
4000
}
m_ActualView
:
{
fileID
:
15
}
m_Panes
:
-
{
fileID
:
15
}
...
...
@@ -70,7 +70,7 @@ MonoBehaviour:
m_MinSize
:
{
x
:
277
,
y
:
192
}
m_MaxSize
:
{
x
:
4002
,
y
:
8042
}
vertical
:
1
controlID
:
1
47
controlID
:
1
34
---
!u!114
&4
MonoBehaviour
:
m_ObjectHideFlags
:
52
...
...
@@ -116,8 +116,8 @@ MonoBehaviour:
y
:
0
width
:
445
height
:
985
m_MinSize
:
{
x
:
234
,
y
:
4
92
}
m_MaxSize
:
{
x
:
10004
,
y
:
140
42
}
m_MinSize
:
{
x
:
234
,
y
:
4
71
}
m_MaxSize
:
{
x
:
10004
,
y
:
140
21
}
vertical
:
1
controlID
:
94
---
!u!114
&6
...
...
@@ -185,10 +185,10 @@ MonoBehaviour:
y
:
30
width
:
1920
height
:
985
m_MinSize
:
{
x
:
713
,
y
:
4
92
}
m_MaxSize
:
{
x
:
18008
,
y
:
140
42
}
m_MinSize
:
{
x
:
713
,
y
:
4
71
}
m_MaxSize
:
{
x
:
18008
,
y
:
140
21
}
vertical
:
0
controlID
:
93
controlID
:
26
---
!u!114
&9
MonoBehaviour
:
m_ObjectHideFlags
:
52
...
...
@@ -251,8 +251,8 @@ MonoBehaviour:
y
:
0
width
:
445
height
:
500
m_MinSize
:
{
x
:
20
4
,
y
:
221
}
m_MaxSize
:
{
x
:
400
4
,
y
:
4021
}
m_MinSize
:
{
x
:
20
0
,
y
:
200
}
m_MaxSize
:
{
x
:
400
0
,
y
:
4000
}
m_ActualView
:
{
fileID
:
16
}
m_Panes
:
-
{
fileID
:
16
}
...
...
@@ -391,7 +391,7 @@ MonoBehaviour:
scrollPos
:
{
x
:
0
,
y
:
0
}
m_SelectedIDs
:
m_LastClickedID
:
0
m_ExpandedIDs
:
9
2
fbffff00000000
m_ExpandedIDs
:
9
e
fbffff00000000
m_RenameOverlay
:
m_UserAcceptedRename
:
0
m_Name
:
...
...
@@ -498,9 +498,9 @@ MonoBehaviour:
m_IsLocked
:
0
m_FolderTreeState
:
scrollPos
:
{
x
:
0
,
y
:
0
}
m_SelectedIDs
:
a0
270000
m_LastClickedID
:
10
14
4
m_ExpandedIDs
:
00000000
92
27000000ca9a3bffffff7f
m_SelectedIDs
:
6e
270000
m_LastClickedID
:
10
09
4
m_ExpandedIDs
:
00000000
60
27000000ca9a3bffffff7f
m_RenameOverlay
:
m_UserAcceptedRename
:
0
m_Name
:
...
...
@@ -528,7 +528,7 @@ MonoBehaviour:
scrollPos
:
{
x
:
0
,
y
:
0
}
m_SelectedIDs
:
m_LastClickedID
:
0
m_ExpandedIDs
:
00000000
92
270000
m_ExpandedIDs
:
00000000
60
270000
m_RenameOverlay
:
m_UserAcceptedRename
:
0
m_Name
:
...
...
Basic Network Library/Library/ScriptAssemblies/Assembly-CSharp.dll
View file @
a5736f1
No preview for this file type
Basic Network Library/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb
View file @
a5736f1
No preview for this file type
Basic Network Library/Library/assetDatabase3
View file @
a5736f1
No preview for this file type
Basic Network Library/obj/Debug/Assembly-CSharp.csproj.CoreCompileInputs.cache
View file @
a5736f1
f4d2a52a7ae35650c675960e6c91d6581973cd3e
c6a089c25c4e53a451f487b9c3cd774f1cfca7c4
...
...
Please
register
or
login
to post a comment