Skip to content

Commit

Permalink
modify read me
Browse files Browse the repository at this point in the history
  • Loading branch information
hiram3512 committed Aug 7, 2018
1 parent f8975e0 commit 855b712
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ It is a lightweight socket solution, you can used it in Unity3d or C# project

### How to use
You can choose use dll or source code, add it to your project.
- Dll: You can download HiSocket dll from here: [HiSocket_xx.zip](https://github.com/hiramtan/HiSocket/releases)
- Source code: source code is in "HiSocket/visual" folder.
 (ps. there also a "HiSocket.Test" unit test project contains some example in source code)
- Dll: [HiSocket_xx.zip](https://github.com/hiramtan/HiSocket/releases)
- Source code: [Source code](https://github.com/hiramtan/HiSocket/tree/master/visual)

Quick Start:
```csharp
private IPackage _package = new PackageExample();
private TcpConnection _tcp;
//tcp example
private IPackage package = new PackageExample();
private TcpConnection tcp;
void Init()
{
_tcp = new TcpConnection(_package);
_tcp.OnConnected += OnConnected;
_tcp.OnReceive += OnReceive;
tcp = new TcpConnection(package);
tcp.OnConnected += OnConnected;
tcp.OnReceive += OnReceive;
//...
//...
}
void OnConnected()
{
//connect success
_tcp.Send(new byte[10]);//send message
_tcp.DisConnect();//disconnect
tcp.Send(new byte[10]);//send message
}

void OnReceive(byte[] bytes)
Expand All @@ -38,6 +37,10 @@ You can choose use dll or source code, add it to your project.
}
```

More example:
- C# project example:[Example](https://github.com/hiramtan/HiSocket/tree/master/visual/HiSocket.Example)
- Unity project example:[Example](https://github.com/hiramtan/HiSocket/tree/master/unity)

-----

### General
Expand Down Expand Up @@ -76,6 +79,17 @@ This project contains:
- Ping: there is a ping plugin you can used, but if you are used in unity3d because of the bug of mono, it will throw an error on .net2.0(.net 4.6 will be fine, also you can use unity's api to get ping time)


### Advanced
- If you are clear about socket, you also can use TcpSocket(UdpSocket) to achieve your logic, anyway the recommend is TcpConnection(UdpConnection).
- You can use API get socket and do extra logic, for example modify time out time
- You can use API get send and receive buffer, for example when disconnect should send all send buffer's data to server? or when reconnect how to process send buffer's data
- OnSocketReceive and OnReceive are diffrent, for example OnSocketReceive size is 100 byte, if user do nothing when uppack OnReceive size is 100. but when user do some zip/unzip(encription.etc) OnReceive size is not 100 anymore.
- You can add many different plugins based on TcpConnection(UdpConnection) to achieve different functions.
- There are a message register base class help user to quick register id and callback(based on reflection)
- Byte block buffer reuse block when some block is free.
- .etc


### Instructions
- Tcp
[Transmission Control Protocol](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)
Expand Down Expand Up @@ -123,12 +137,7 @@ If use Udp connection shold define send and receive's buffer size.
- Bytes message
- Encription

### Advanced
- If you are clear about socket, you also can use TcpSocket(UdpSocket) to achieve your logic, anyway the recommend is TcpConnection(UdpConnection).
- You can add many different plugins based on TcpConnection(UdpConnection) to achieve different functions.
- There are a message register base class help user to quick register id and callback(based on reflection)
- Byte block buffer use linked list and reuse block when some block is free.
- .etc

---------

### Example
Expand Down
41 changes: 24 additions & 17 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,37 @@

### 如何使用
可以选择使用dll或者使用源码,把它添加到自己的工程中即可使用.
- Dll: 可以从此下载 HiSocket dll: [HiSocket_xx.zip](https://github.com/hiramtan/HiSocket/releases)
- 源码: 源码在此文件夹中"HiSocket/visual"
(ps. 源码的单元测试项目HiSocket.Test包含一些示例代码)
- Dll: [HiSocket_xx.zip](https://github.com/hiramtan/HiSocket/releases)
- 源码: [源码](https://github.com/hiramtan/HiSocket/tree/master/visual)


快速开始:
```csharp
private IPackage _package = new PackageExample();
private TcpConnection _tcp;
//tcp example
private IPackage package = new PackageExample();
private TcpConnection tcp;
void Init()
{
_tcp = new TcpConnection(_package);
_tcp.OnConnected += OnConnected;
_tcp.OnReceive += OnReceive;
tcp = new TcpConnection(package);
tcp.OnConnected += OnConnected;
tcp.OnReceive += OnReceive;
//...
//...
}
void OnConnected()
{
//connect success
_tcp.Send(new byte[10]);//send message
_tcp.DisConnect();//disconnect
tcp.Send(new byte[10]);//send message
}

void OnReceive(byte[] bytes)
{
//get message from server
}
```
更多示例:
- C#项目示例:[示例](https://github.com/hiramtan/HiSocket/tree/master/visual/HiSocket.Example)
- Unity项目示例:[示例](https://github.com/hiramtan/HiSocket/tree/master/unity)

-----

Expand Down Expand Up @@ -74,6 +76,17 @@
- 如果使用Udp协议需要声明缓冲区大小.
- Ping: 源码包含一个Ping插件可以使用,但是如果用在unity3d工程中会报错(因为mono的问题,在.net2.0会报错.net4.6可以正常使用)

### 高级功能
- 如果对Socket很熟悉,也可以使用TcpSocket(UdpSocket)来实现功能,但是还是推荐使用TcpConnection(UdpConnection)的方式.
- 通过接口可以访问底层Socket对象扩展逻辑,比如修改超时时间.
- 通过接口可以获得发送接收缓冲区,比如断开连接时是否要将发送缓冲区数据全部发出?重连后怎样处理发送缓冲区的数据.
- OnSocketReceive和OnReceive是不同的,比如当OnSocketReceive接受大小是100字节,当用户解包时不做操作,OnReceive大小是100字节,当用户解包时做解压缩(解密等)操作后,OnReceive大小不再是100.
- 可以向TcpConnection(UdpConnection)添加不同的插件完成所需的功能,
- 注册基类可以方便快速注册消息(基于反射)
- Byte block buffer 采用有序链表实现,当有区块空闲时会重用区块.
- .etc
---------


### 介绍
- Tcp
Expand Down Expand Up @@ -122,13 +135,7 @@ Udp协议提供不可靠的报文消息,用户无法知道当前连接状态,但
- 字节消息
- 加密

### 高级功能
- 如果对Socket很熟悉,也可以使用TcpSocket(UdpSocket)来实现功能,但是还是推荐使用TcpConnection(UdpConnection)的方式.
- 可以向TcpConnection(UdpConnection)添加不同的插件完成所需的功能,
- 注册基类可以方便快速注册消息(基于反射)
- Byte block buffer 采用有序链表实现,当有区块空闲时会重用区块.
- .etc
---------


### Example
**HiSocketExample****HiSocket.unitypackage**有很多示例, 其中有一些如下:
Expand Down

0 comments on commit 855b712

Please sign in to comment.