forked from hiram3512/HiSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (53 loc) · 1.38 KB
/
Program.cs
File metadata and controls
58 lines (53 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/***************************************************************
* Description:
*
* Documents: https://github.com/hiramtan/HiSocket
* Author: hiramtan@live.com
***************************************************************/
using HiFramework;
using HiFramework.Unity;
using HiSocket.Example;
using HiSocket.Tcp;
using UnityEngine;
namespace HiSocket.Example_Unity
{
class Program
{
static void Main(string[] args)
{
}
}
public class Example : MonoBehaviour
{
private ITickComponent tick;
private IMainThread mainThread;
// Use this for initialization
void Start()
{
Center.Init(new UnityBinder());
tick = Center.Get<ITickComponent>();
Connect();
}
// Update is called once per frame
void Update()
{
tick.Tick(Time.deltaTime);
}
TcpConnection tcp;
void Connect()
{
var package = new PackageExample();
tcp = new TcpConnection(package);
tcp.OnReceiveMessage += OnReceive;
tcp.Connect("127.0.0.1", 999);
}
void OnReceive(byte[] message)
{
mainThread.RunOnMainThread(OnMainThread,message);
}
void OnMainThread(object message)
{
var data = message as byte[];
}
}
}