mirror of
https://github.com/beykery/cocosocket.git
synced 2026-09-03 06:15:40 +08:00
BIN
cocosocket4unity/.vs/cocosocket4unity/v14/.suo
Normal file
BIN
cocosocket4unity/.vs/cocosocket4unity/v14/.suo
Normal file
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace cocosocket4unity
|
||||
{
|
||||
public class LVProtocal : Protocal
|
||||
public class LVProtocol : Protocol
|
||||
{
|
||||
private int status;
|
||||
private int h;
|
||||
@@ -10,7 +10,7 @@ namespace cocosocket4unity
|
||||
private short len;
|
||||
private ByteBuf frame;
|
||||
|
||||
public LVProtocal ()
|
||||
public LVProtocol ()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -41,27 +41,27 @@ namespace cocosocket4unity
|
||||
Console.WriteLine(arr.value);
|
||||
}
|
||||
Console.Read();
|
||||
*/
|
||||
/**
|
||||
long time_JAVA_Long = 1446050129676L;//java长整型日期,毫秒为单位
|
||||
DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);
|
||||
long tricks_1970 = dt_1970.Ticks;//1970年1月1
|
||||
long time_tricks = tricks_1970 + time_JAVA_Long * 10000;//日志日期刻度
|
||||
DateTime dt = new DateTime(time_tricks).AddHours(8);//转化为DateTime
|
||||
Console.WriteLine(string.Format("{0:G}", dt));
|
||||
Console.Read();
|
||||
*/
|
||||
/**
|
||||
SocketListner listner = new TestListner ();
|
||||
long time_JAVA_Long = 1446050129676L;//java长整型日期,毫秒为单位
|
||||
DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);
|
||||
long tricks_1970 = dt_1970.Ticks;//1970年1月1
|
||||
long time_tricks = tricks_1970 + time_JAVA_Long * 10000;//日志日期刻度
|
||||
DateTime dt = new DateTime(time_tricks).AddHours(8);//转化为DateTime
|
||||
Console.WriteLine(string.Format("{0:G}", dt));
|
||||
Console.Read();
|
||||
*/
|
||||
/**
|
||||
SocketListener listener = new TestListener ();
|
||||
USocket us = new USocket ();
|
||||
us.setLister (listner);
|
||||
Protocal p = new Varint32HeaderProtocol ();
|
||||
//Protocal p = new LVProtocal();
|
||||
us.setProtocal (p);
|
||||
us.setListener (listener);
|
||||
Protocol p = new Varint32HeaderProtocol ();
|
||||
//Protocol p = new LVProtocol();
|
||||
us.setProtocol (p);
|
||||
us.Connect ("localhost", 4887);
|
||||
Console.Read();
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace cocosocket4unity
|
||||
{
|
||||
public interface Protocal
|
||||
public interface Protocol
|
||||
{
|
||||
ByteBuf TranslateFrame (ByteBuf src);
|
||||
int HeaderLen();
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace cocosocket4unity
|
||||
{
|
||||
public abstract class SocketListner
|
||||
public abstract class SocketListener
|
||||
{
|
||||
abstract public void OnMessage(USocket us,ByteBuf bb);
|
||||
abstract public void OnClose(USocket us,bool fromRemote);
|
||||
@@ -7,9 +7,9 @@ using System.IO;
|
||||
using protocol;
|
||||
namespace cocosocket4unity
|
||||
{
|
||||
public class TestListner : SocketListner
|
||||
public class TestListener : SocketListener
|
||||
{
|
||||
public TestListner ()
|
||||
public TestListener ()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace cocosocket4unity
|
||||
{
|
||||
|
||||
Console.WriteLine ("收到数据:");
|
||||
bb.ReaderIndex (us.getProtocal().HeaderLen());
|
||||
bb.ReaderIndex (us.getProtocol().HeaderLen());
|
||||
|
||||
int cmd = bb.ReadShort();
|
||||
Type t=null;
|
||||
@@ -10,8 +10,8 @@ namespace cocosocket4unity
|
||||
public class USocket
|
||||
{
|
||||
private Socket clientSocket;
|
||||
private SocketListner listner;
|
||||
private Protocal protocal;
|
||||
private SocketListener listener;
|
||||
private Protocol protocol;
|
||||
private string ip;
|
||||
private int port;
|
||||
private int status;
|
||||
@@ -37,10 +37,10 @@ namespace cocosocket4unity
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public USocket(SocketListner listner, Protocal protocal)
|
||||
public USocket(SocketListener listener, Protocol protocol)
|
||||
{
|
||||
this.listner = listner;
|
||||
this.protocal = protocal;
|
||||
this.listener = listener;
|
||||
this.protocol = protocol;
|
||||
buf = new ByteBuf(4096);
|
||||
//queue = new BlockingQueue<ByteBuf>(5000);
|
||||
}
|
||||
@@ -76,35 +76,35 @@ namespace cocosocket4unity
|
||||
//Thread t = new Thread(new ThreadStart(send));//启动发送线程,同步发送
|
||||
//t.IsBackground = true;
|
||||
//t.Start();
|
||||
this.listner.OnOpen(this);
|
||||
this.listener.OnOpen(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.status = STATUS_CLOSED;
|
||||
this.serverClose = false;
|
||||
this.listner.OnClose(this, false);
|
||||
this.listener.OnClose(this, false);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 装入一个监听器
|
||||
*/
|
||||
public void setLister(SocketListner listner)
|
||||
public void setListener(SocketListener listener)
|
||||
{
|
||||
this.listner = listner;
|
||||
this.listener = listener;
|
||||
}
|
||||
/**
|
||||
* 装入一个协议解析器
|
||||
*/
|
||||
public void setProtocal(Protocal p)
|
||||
public void setProtocol(Protocol p)
|
||||
{
|
||||
this.protocal = p;
|
||||
this.protocol = p;
|
||||
}
|
||||
/**
|
||||
* 协议
|
||||
*/
|
||||
public Protocal getProtocal()
|
||||
public Protocol getProtocol()
|
||||
{
|
||||
return this.protocal;
|
||||
return this.protocol;
|
||||
}
|
||||
public int getStatus()
|
||||
{
|
||||
@@ -151,14 +151,14 @@ namespace cocosocket4unity
|
||||
clientSocket.Close();
|
||||
this.status = STATUS_CLOSED;
|
||||
this.serverClose = serverClose;
|
||||
this.listner.OnClose(this, this.serverClose);
|
||||
this.listener.OnClose(this, this.serverClose);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.status = STATUS_CLOSED;
|
||||
this.serverClose = serverClose;
|
||||
this.listner.OnClose(this, this.serverClose);
|
||||
this.listener.OnClose(this, this.serverClose);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -214,7 +214,7 @@ namespace cocosocket4unity
|
||||
catch (Exception e)
|
||||
{
|
||||
this.status = STATUS_CLOSED;
|
||||
this.listner.OnError(this, e.StackTrace + e.Message);
|
||||
this.listener.OnError(this, e.StackTrace + e.Message);
|
||||
this.Close(true);
|
||||
}
|
||||
}
|
||||
@@ -234,10 +234,10 @@ namespace cocosocket4unity
|
||||
buf.WriterIndex(len);
|
||||
while (true)
|
||||
{
|
||||
ByteBuf frame = this.protocal.TranslateFrame(buf);
|
||||
ByteBuf frame = this.protocol.TranslateFrame(buf);
|
||||
if (frame != null)
|
||||
{
|
||||
this.listner.OnMessage(this, frame);
|
||||
this.listener.OnMessage(this, frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
using System;
|
||||
namespace cocosocket4unity
|
||||
{
|
||||
public class Varint32HeaderProtocol : Protocal
|
||||
public class Varint32HeaderProtocol : Protocol
|
||||
{
|
||||
|
||||
private const int STATUS_HEADER = 0;//读头
|
||||
|
||||
@@ -51,8 +51,8 @@
|
||||
<Compile Include="Frame.cs" />
|
||||
<Compile Include="Output.cs" />
|
||||
<Compile Include="ProtoAttribute.cs" />
|
||||
<Compile Include="Protocal.cs" />
|
||||
<Compile Include="LVProtocal.cs" />
|
||||
<Compile Include="Protocol.cs" />
|
||||
<Compile Include="LVProtocol.cs" />
|
||||
<Compile Include="TestEnum.cs" />
|
||||
<Compile Include="TestKcp.cs" />
|
||||
<Compile Include="TestRequest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user