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