|
|
|
@ -21,13 +21,13 @@ namespace JXSoft
@@ -21,13 +21,13 @@ namespace JXSoft
|
|
|
|
|
{ |
|
|
|
|
this.RegisterEvent<onLinkException>(e=> { |
|
|
|
|
setLinkState((int)TCPLinkState.LinkTimeOut); |
|
|
|
|
this.GetUtility<TCPUtility>().CloseTCPClient(); |
|
|
|
|
this.GetUtility<TCPClientUtility>().CloseTCPClient(); |
|
|
|
|
}); |
|
|
|
|
//注册重写发送事件 |
|
|
|
|
this.RegisterEvent<RequestMsgEvent>(e => { |
|
|
|
|
if (this.GetUtility<TCPUtility>().isOpenTCP) |
|
|
|
|
if (this.GetUtility<TCPClientUtility>().isOpenTCP) |
|
|
|
|
{ |
|
|
|
|
this.GetUtility<TCPUtility>().sendData(e.req.toProtocolData()); |
|
|
|
|
this.GetUtility<TCPClientUtility>().sendData(e.req.toProtocolData()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -70,9 +70,9 @@ namespace JXSoft
@@ -70,9 +70,9 @@ namespace JXSoft
|
|
|
|
|
public void linkServer() { |
|
|
|
|
if (tcpState == TCPLinkState.Linking) |
|
|
|
|
{ |
|
|
|
|
if (!this.GetUtility<TCPUtility>().isOpenTCP) { |
|
|
|
|
if (!this.GetUtility<TCPClientUtility>().isOpenTCP) { |
|
|
|
|
|
|
|
|
|
bool isSuccess = this.GetUtility<TCPUtility>().StartTCPClient(tcpAddress, tcpPort); |
|
|
|
|
bool isSuccess = this.GetUtility<TCPClientUtility>().StartTCPClient(tcpAddress, tcpPort); |
|
|
|
|
if (isSuccess) { |
|
|
|
|
setLinkState((int)TCPLinkState.LinkSucess); |
|
|
|
|
} |
|
|
|
@ -90,10 +90,10 @@ namespace JXSoft
@@ -90,10 +90,10 @@ namespace JXSoft
|
|
|
|
|
{ |
|
|
|
|
if (tcpState == TCPLinkState.LinkSucess) |
|
|
|
|
{ |
|
|
|
|
if (this.GetUtility<TCPUtility>().isOpenTCP) |
|
|
|
|
if (this.GetUtility<TCPClientUtility>().isOpenTCP) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
this.GetUtility<TCPUtility>().CloseTCPClient(); |
|
|
|
|
this.GetUtility<TCPClientUtility>().CloseTCPClient(); |
|
|
|
|
setLinkState((int)TCPLinkState.NoIp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -126,7 +126,7 @@ namespace JXSoft
@@ -126,7 +126,7 @@ namespace JXSoft
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region util |
|
|
|
|
public class TCPUtility : IUtility |
|
|
|
|
public class TCPClientUtility : IUtility |
|
|
|
|
{ |
|
|
|
|
public string tcpAddress; |
|
|
|
|
public int tcpPort; |
|
|
|
@ -140,12 +140,12 @@ namespace JXSoft
@@ -140,12 +140,12 @@ namespace JXSoft
|
|
|
|
|
public Thread reciveT; |
|
|
|
|
public bool isTimeOut = false; |
|
|
|
|
|
|
|
|
|
public TCPUtility() |
|
|
|
|
public TCPClientUtility() |
|
|
|
|
{ |
|
|
|
|
Debug.LogWarning("使用无参数构造tcp时,需要手动开启tcp服务"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public TCPUtility(string tcpAddress, int tcpPort) |
|
|
|
|
public TCPClientUtility(string tcpAddress, int tcpPort) |
|
|
|
|
{ |
|
|
|
|
this.tcpAddress = tcpAddress; |
|
|
|
|
this.tcpPort = tcpPort; |
|
|
|
|