A most basic TCT connection is established with the code below:
// Initialization IPEndPoint m_IpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.71"), 5000); Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); NetworkStream m_Stream = new NetworkStream(m_Socket); // Read/write operations m_Stream.Write(System.Text.Encoding.ASCII.GetBytes("Hello world!"), 0, 12); byte read_buffer = new byte; m_Stream.Read(read_buffer, 0, 4096); // Closing open resources m_Stream.Close(); m_Socket.Shutdown(SocketShutdown.Both); m_Socket.Close();
When communicating through TCP we specify both local and foregn sockets, right? Correct me if I'm wrong, this is my first network program.
I want to ask these question:
What does "127.0.0.71:5000" specify in my code? Is it local or foreign socket address? If it is local, how can I specify the foreign one (and vice versa)?
Looking for your reply.
Edited 6 Years Ago by hkBattousai: n/a