Two Way TCP Communication in UWP Unity
I want to connect the server (my PC) and client (Hololens) with TCP socketing. I found many codes on the internet which use the async tasks to read write without blocking the rest of the tasks. I have already tested it and it worked fine even for two-way communication. However, my open challenge is that I need to call read whenever the user clicks a specific button followed by call Writing with a specific delay. Now one simplified method coming to my mind is:
async task Connecting(){
await connect(IP,PORT)); // send the text to pc
}
async task Writing(string text){
await write (text); // send the text to pc
}
async task Reading(){
await result = read (); // read result from pc
}
void onbuttonclick(){
Writing(button.text);
delay(500);
Reading()}
Is the way correct?
Can we check the connection only one time? Not whenever we want to read or write?
Is this way efficient? Or better to read and write in a while loop and extract the result by clicking the button?
I know the above code is not complete and has a bunch of mistakes but I just wanted to give you an overview of my idea.