|
@@ -24,17 +24,20 @@ public class client : MonoBehaviour
|
|
|
|
|
|
private bool isConnect = false;
|
|
|
private float times = 0;
|
|
|
-
|
|
|
+ private string ipPath;
|
|
|
public Queue<String> queueRecMsg;
|
|
|
void Start()
|
|
|
{
|
|
|
- ClickConnect();
|
|
|
+ ipPath = Application.persistentDataPath + "/Ipconfig/" + "ip.txt";
|
|
|
+ Debug.Log(ipPath);
|
|
|
+ SettingIP();
|
|
|
+
|
|
|
|
|
|
- TimerMgr.Instance.CreateTimer(()=> { SendData(); }, 0.2f, -1);
|
|
|
+ TimerMgr.Instance.CreateTimer(()=> { SendData(); }, 0.1f, -1);
|
|
|
queueRecMsg = new Queue<string>();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void Update()
|
|
|
{
|
|
|
if(!isConnect)
|
|
@@ -43,11 +46,42 @@ public class client : MonoBehaviour
|
|
|
if(times>3f)
|
|
|
{
|
|
|
times = 0;
|
|
|
-
|
|
|
+ ClickConnect();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void SettingIP()
|
|
|
+ {
|
|
|
+ if (File.Exists(ipPath))
|
|
|
+ {
|
|
|
+ FileStream fileStream = new FileStream(ipPath, FileMode.Open, FileAccess.Read);
|
|
|
+ fileStream.Seek(0, SeekOrigin.Begin);
|
|
|
+
|
|
|
+ byte[] bytes = new byte[fileStream.Length];
|
|
|
+
|
|
|
+ fileStream.Read(bytes, 0, (int)fileStream.Length);
|
|
|
+
|
|
|
+ fileStream.Close();
|
|
|
+ fileStream.Dispose();
|
|
|
+ fileStream = null;
|
|
|
+
|
|
|
+ inputIp = System.BitConverter.ToString(bytes);
|
|
|
+ ClickConnect();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(Application.persistentDataPath + "/Ipconfig");
|
|
|
+ FileInfo fileInfo = new FileInfo(ipPath);
|
|
|
+
|
|
|
+ FileStream FileWriter = fileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
|
|
|
+ UTF8Encoding encoding = new UTF8Encoding();
|
|
|
+ FileWriter.Write(encoding.GetBytes("192.168.50.17"), 0, encoding.GetByteCount("192.168.50.17"));
|
|
|
+ FileWriter.Close();
|
|
|
+ SettingIP();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void ClickConnect()
|
|
|
{
|
|
@@ -132,10 +166,7 @@ public class client : MonoBehaviour
|
|
|
Message = NetWorkLANManager.Instance.queueMsg.Dequeue();
|
|
|
clickSend = true;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -154,8 +185,6 @@ public class client : MonoBehaviour
|
|
|
clickSend = false;
|
|
|
if (socketSend.Connected)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
byte[] buffer = new byte[1024 * 6];
|
|
|
buffer = Encoding.UTF8.GetBytes(Message);
|
|
|
socketSend.Send(buffer);
|