Socket Beginsend Gönderme Problemi
-
Bağlantı sağlandığı zaman clientin servera hello mesajını göndermesini istiyorum. Fakat mesajı clienti kapattığım zaman servera iletiyor.
Nerede hata yaptığımı bulamadım. Kodlarım aşağıda.
byte[] , asd; void ConnectToServer() { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { IAsyncResult result = socket.BeginConnect("127.0.0.1", 6789, EndConnect, null); } catch (Exception e) { Debug.Log("Error : " + e.Message); } } void EndConnect(IAsyncResult iar) { socket.EndConnect(iar); socket.NoDelay = true; Debug.Log("Client connected"); asd = System.Text.Encoding.ASCII.GetBytes("hello"); SendReply(asd); } void SendReply(byte[] msgArray) { socket.BeginSend(msgArray, 0, msgArray.Length, SocketFlags.None, EndSend, msgArray); } void EndSend(IAsyncResult iar) { int sentByte = socket.EndSend(iar); Debug.Log(sentByte + " byte sent"); }
-
Güncel