You're not far off!
Here's a few things:
I'd replace this:
IPAddress ipAd = IPAddress.Parse ("127.0.0.1");
TcpListener myList = new TcpListener (ipAd, 8001);
with this:
TcpListener myList = new TcpListener (IPAddress.Any, 8001);
Reason being that 127.0.0.1 will only work on your computer and not incoming connections from other computers.
On the server you are accepting a socket, but on the client a TcpClient. Use the same (TcpClient) on both sides. Once the connection is established both ends work exactly the same way then. Use
AcceptTcpClient
instead of
AcceptSocket
.
When reading and writing to/from the stream, you need to put the read/write calls in a loop. Not all the data can be guaranteed in a single call as it gets lumped in packets on the wire. If you try to read 8k of data but the read call only returns 5000 bytes, you need to call it again to collect the rest.
As for the original question you need to determine if connections are going to be brief affairs (threadpool) or long-running things (new thread). Either way, put the Accept in a loop, and pass the supplied TcpClient as the parameter to the threadstart. If that doesn't make sense, let me know and I'll explain further.