public class Echo : MonoBehaviour
{
Socket socket;
public TMP_InputField reqField;
public TMP_Text responseText;
public void Connect()
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("127.0.0.1", 8888);
}
public void Send()
{
string sendStr = reqField.text;
byte[] sendBytes = System.Text.Encoding.UTF8.GetBytes(sendStr);
socket.Send(sendBytes);
byte[] readBuff = new byte[1024];
int count = socket.Receive(readBuff);
string recevieStr = System.Text.Encoding.UTF8.GetString(readBuff, 0, count);
responseText.text = recevieStr;
socket.Close();
}
}