using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
///
/// Summary description for Class1.
///
class TCPClient
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
try
{
TcpClient client = new TcpClient();
client.Connect(Dns.GetHostName(), 8080);
NetworkStream writer = client.GetStream();
StreamReader reader = new StreamReader(client.GetStream());
string data;
byte[] sendBytes;
while(true)
{
Console.Write("Enter a message to send('quit' to end): ");
data = Console.ReadLine();
data = data + "\r\n";
sendBytes = Encoding.ASCII.GetBytes(data);
writer.Write(sendBytes,0,sendBytes.Length);
Console.Write("Sending message: " + Encoding.ASCII.GetString(sendBytes));
if (data.IndexOf("quit") > -1) break;
data = reader.ReadLine();
Console.Write("Received message: " + data + "\n");
}
client.Close();
}//end try
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.WriteLine("the listener has probably not started");
}
}
}