static void Main(string[] args) { Console.WriteLine("Connectando com servidor"); TCPListener servertcp = new TCPListener("127.0.0.1", 7171, 1024, Server_OnReceiveHandler); servertcp.Connect(); UDPListener server = new UDPListener("192.168.0.100", 7172, 1024, Server_OnReceiveHandler); for (int i = 0; i < 10; i++) { using (ConWriter writer = new ConWriter(0)) { writer.Send("Teste envia UDP" + i); server.Send(writer); } } string texto = ""; while (texto != "fim") { texto = Console.ReadLine(); ConWriter writer1 = new ConWriter(1); writer1.Send(texto); Console.WriteLine("Tamanho do buffer: " + writer1._buffer.Length); server.Send(writer1); } }
void ServerUpdate() { if (m_HasClientConnected == false) { if (m_ServerSession.GetRecvedData(m_ServerRecvedData)) { while (m_ServerRecvedData.Count != 0) { m_HasClientConnected = true; m_ServerRecvedData.Dequeue(); } } } else { Vector3 toTarget = m_ServerTargetPos - m_ServerPos; if (toTarget.sqrMagnitude < 0.5f) { m_ServerTargetPos = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10)); } else { toTarget.Normalize(); m_ServerPos += 6 * Time.deltaTime * toTarget; m_ServerRot = Quaternion.LookRotation(toTarget); } if (Time.time > m_NextSyncTime) { StateMsg msg = new StateMsg(); msg.TargetPosition = m_ServerPos; msg.TargetOrientation = m_ServerRot; msg.TimeStamp = Time.time; m_ServerSession.Send(msg.Serialize()); m_NextSyncTime = Time.time + 0.2f; } ServerObjectTF.position = m_ServerPos; ServerObjectTF.rotation = m_ServerRot; } }
IEnumerator DelaySend(byte[] data, float delay) { yield return(new WaitForSeconds(delay)); m_ServerSession.Send(data); }