Well, first, is this program the client or the server? To really run it with two processes, you'll want one program to be the client, and another to be the server.
The server program should execute the Bind, Listen and Accept; while the client program executes the Connect method to connect to the server program. You appear to be doing both in the same program. You can actually do that...
In the server program, you need a local Socket object to perform the Bind and Listen. You also perform the Accept (this is where the server "comes alive" when a remote client connects to it), and the return value from the Accept is *another* socket - the socket to the remote client that just connected. The original socket can then go back to the Listen and wait for another client to connect.
When you have the programs separated, execute the server program first, then execute the client. If coded correctly, the client will connect up and you will be able to pass data back and forth.
Client:
m_IpEndPointForeign = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000);
m_SocketForeign = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_SocketForeign.Connect(m_IpEndPointForeign);
m_Stream = new NetworkStream(m_SocketForeign);
// Read & Write operations
m_Stream.Write(...); // Implementation left to you...
m_Stream.Close();
m_SocketForeign.Shutdown(SocketShutdown.Both);
m_SocketForeign.Close();
Server:
m_IpEndPointLocal = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000);
m_SocketLocal = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_SocketLocal.Bind(m_IpEndPointLocal);
m_SocketLocal.Listen(10);
Socket m_SocketClient = m_SocketLocal.Accept();
m_Stream = new NetworkStream(m_SocketClient);
// Read & Write operations
m_Stream.Read(); // Actual Read() implementation left to coder...
m_Stream.Close();
m_SocketClient.Shutdown(SocketShutdown.Both);
m_SocketClient.Close();
m_SocketLocal.Shutdown(SocketShutdown.Both);
m_SocketLocal.Close();
Notice that the client and server are using the same port.
The parameter to Listen() is the number of buffered connections the Listen command will handle. That is, up to 10 clients can be "buffered" up, awaiting connection. The 11th client that attempts (assuming the server program is not fast enough to accept the connection requests) will be turned away with an error (an error, of course, that the client program should be checking for!)
For reading and writing on NetworkStream objects, investigate the StreamReader and StreamWriter classes...