|
|
@ -14,7 +14,7 @@ namespace JXSoft { |
|
|
|
protected override void Init() |
|
|
|
protected override void Init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.RegisterUtility(new TCPUtility()); |
|
|
|
this.RegisterUtility(new TCPUtility()); |
|
|
|
this.RegisterModel(new TCPEventModel()); |
|
|
|
this.RegisterModel(new TCPClientModel()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public class TCPClientView : MonoBehaviour,IController,ICanRegisterEvent |
|
|
|
public class TCPClientView : MonoBehaviour,IController,ICanRegisterEvent |
|
|
@ -50,13 +50,13 @@ namespace JXSoft { |
|
|
|
if (e.linkState == (int)TCPLinkState.Linking) |
|
|
|
if (e.linkState == (int)TCPLinkState.Linking) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Debug.Log("TCP¿ªÊ¼Á´½Ó"); |
|
|
|
Debug.Log("TCP¿ªÊ¼Á´½Ó"); |
|
|
|
this.GetModel<TCPEventModel>().linkServer(); |
|
|
|
this.GetModel<TCPClientModel>().linkServer(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (e.linkState == (int)TCPLinkState.LinkSucess) |
|
|
|
if (e.linkState == (int)TCPLinkState.LinkSucess) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Debug.Log("TCPÁ´½Ó³É¹¦"); |
|
|
|
Debug.Log("TCPÁ´½Ó³É¹¦"); |
|
|
|
this.GetModel<TCPEventModel>().onReceive<LinkSuccessResponse>(); |
|
|
|
this.GetModel<TCPClientModel>().onReceive<LinkSuccessResponse>(); |
|
|
|
this.GetModel<TCPEventModel>().sendRequestCommand(new LinkTCPRequest(deviceId)); |
|
|
|
this.GetModel<TCPClientModel>().sendRequestCommand(new LinkTCPRequest(deviceId)); |
|
|
|
onTCPLinkSuccess.Invoke(); |
|
|
|
onTCPLinkSuccess.Invoke(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (e.linkState == (int)TCPLinkState.LinkFaild) |
|
|
|
if (e.linkState == (int)TCPLinkState.LinkFaild) |
|
|
@ -71,23 +71,23 @@ namespace JXSoft { |
|
|
|
if (e.res.GetType() == typeof(LinkSuccessResponse)) |
|
|
|
if (e.res.GetType() == typeof(LinkSuccessResponse)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Debug.Log("Link Server success"); |
|
|
|
Debug.Log("Link Server success"); |
|
|
|
this.GetModel<TCPEventModel>().offReceive<LinkSuccessResponse>(); |
|
|
|
this.GetModel<TCPClientModel>().offReceive<LinkSuccessResponse>(); |
|
|
|
onServerConnected.Invoke(); |
|
|
|
onServerConnected.Invoke(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.GetModel<TCPEventModel>().setLinkState((int)TCPLinkState.NoIp); |
|
|
|
this.GetModel<TCPClientModel>().setLinkState((int)TCPLinkState.NoIp); |
|
|
|
this.GetModel<TCPEventModel>().setIP(tcpAddress, tcpPort); |
|
|
|
this.GetModel<TCPClientModel>().setIP(tcpAddress, tcpPort); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void restartTCPService() { |
|
|
|
public void restartTCPService() { |
|
|
|
onTCPReLink.Invoke(); |
|
|
|
onTCPReLink.Invoke(); |
|
|
|
this.GetModel<TCPEventModel>().closeServer(); |
|
|
|
this.GetModel<TCPClientModel>().closeServer(); |
|
|
|
StartCoroutine(waitTwoSecond()); |
|
|
|
StartCoroutine(waitTwoSecond()); |
|
|
|
} |
|
|
|
} |
|
|
|
public IEnumerator waitTwoSecond() { |
|
|
|
public IEnumerator waitTwoSecond() { |
|
|
|
yield return new WaitForSeconds(2.0f); |
|
|
|
yield return new WaitForSeconds(2.0f); |
|
|
|
this.GetModel<TCPEventModel>().setLinkState((int)TCPLinkState.Linking); |
|
|
|
this.GetModel<TCPClientModel>().setLinkState((int)TCPLinkState.Linking); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame |
|
|
|
// Update is called once per frame |
|
|
@ -98,7 +98,7 @@ namespace JXSoft { |
|
|
|
{ |
|
|
|
{ |
|
|
|
GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); |
|
|
|
GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); |
|
|
|
item.GetComponentInChildren<Text>().text = tcpUtil.receivedData; |
|
|
|
item.GetComponentInChildren<Text>().text = tcpUtil.receivedData; |
|
|
|
this.GetModel<TCPEventModel>().onDataRecived.Invoke(tcpUtil.receivedData); |
|
|
|
this.GetModel<TCPClientModel>().onDataRecived.Invoke(tcpUtil.receivedData); |
|
|
|
} |
|
|
|
} |
|
|
|
if (tcpUtil.getTimeOutState() && tcpUtil.isOpenTCP) |
|
|
|
if (tcpUtil.getTimeOutState() && tcpUtil.isOpenTCP) |
|
|
|
{ |
|
|
|
{ |
|
|
|