new TcpClient( String ip, int port)
using System;
using System.IO;
using System.Net.Sockets;
class MainClass
{
const int echoPort = 7;
[STAThread]
static void Main(string[] args)
{
using ( TcpClient tc = new TcpClient( "localhost", echoPort ) )
{
NetworkStream ns = tc.GetStream();
StreamWriter sw = new StreamWriter( ns );
StreamReader sr = new StreamReader( ns );
sw.WriteLine( "test message" );
sw.Flush();
System.Console.WriteLine( sr.ReadLine() );
}
}
}
Related examples in the same category