0

I am creating TCP dedicated server for my game. But I run into wall once more unfortunately.

How can I listen to Connections, while waiting for user input (commands) ? For example my code is going to run as it Should, and when I write in console callClient, it will invoke that function? because with simple while loop it is impossible (as while loop blocks). My server architecture is in this question: C# Tcp BeginAcceptTcpClient throws ObjectDisposedException Different thread is also out of question, I wouldn't be able to call the callClient function which would be in different thread

Aldabeth
  • 63
  • 5
  • Your `AcceptTcpClient()` and `AcceptSocket()` methods are not blocking. You should be able to listen to user input at the same time. Did you try it? (Yeah. Me again :)) – Oguz Ozgul May 03 '20 at 20:30
  • What I mean is, if you execute a `Console.ReadLine()` after calling one of these methods, you will be waiting for user input, and, if any connection request comes at the same time, it will invoke your async callback function and you will be able to accept it. – Oguz Ozgul May 03 '20 at 20:32
  • Yes, and thank you. but that is not something I want. I don't want to wait for user input. I want to catch the user input if he inputs something. No matter when. – Aldabeth May 03 '20 at 20:36
  • And this is achieved using Console.ReadLine, isn’t it? Or ReadKey? – Oguz Ozgul May 03 '20 at 20:38
  • Your question is too broad, but also is a duplicate of _many_ other too-broad questions already asked and answers on Stack Overflow. See marked duplicate, along with e.g. https://stackoverflow.com/search?tab=votes&q=%5bc%23%5d%20tcp%20async – Peter Duniho May 03 '20 at 20:48
  • Nothing helps me (from what u send peter) there is nowhere question like mine. Console.ReadLine does indeed read when I write something in console, or it allows me to for example save the user input in string. But, I need it like this: (example code) : https://pastebin.com/53Z7f3vP this code doesn't work, cause the while loop blocks. – Aldabeth May 03 '20 at 21:15

0 Answers0