I'm a client : public class GuiTestCS : MonoBehaviour { Socket sock; void Start () { IPAddress host = IPAddress.Parse("10.4.2.215"); IPEndPoint hostip = new IPEndPoint(host, 3333); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { sock.Connect(hostip); print("Connected successful"); } catch (SocketException e) { print("Problem connecting to host"); print(e.ToString()); return; } string message = "HungKV\n"; sock.Send(Encoding.ASCII.GetBytes(message)); byte[] data = new byte[1024]; int receivedDataLength = sock.Receive(data); string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); } void Update () { } } I can connect to server, send message to server, but i can't receive message form server. (It hang when receive message) Someone help me thanks!
I just test, and got the same situation. But sometime, I can receive messages from server when I change sent message. Anyone know about this? //=========== //edit I see Server send char '0' after message need to send, so it makes infinite loop at socket.Receive(buffer) => hang Unity.
http://www.unifycommunity.com/wiki/index.php?title=Simple_TCP/IP_Client_-_Server Maybe that will help.