guys

this is urgent please help me.

I am trying to build a simple socket application which can keep sending data to a port. I have this following code which i got from net.

private void sendToPort()
{

IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

socket.Bind(ip);
socket.Listen(10);
Console.WriteLine("Waiting for a client...");
Socket client = socket.Accept();
IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port);
//label1.Text = "Connected with " + clientep.Address + " at " + clientep.Port;

string welcome = TextBox1.Text+"\n";
byte[] data = new byte[1024];
data = Encoding.ASCII.GetBytes(welcome);
client.Send(data, data.Length, SocketFlags.None);

Console.WriteLine("Disconnected from {0}", clientep.Address);
//label1.Text = "Disconnected from {0}";
client.Close();
socket.Close();
}

This code is ok but the problem is after each data is sent it closes the connection and for the next data transfer it opens a fresh connection. I dont want this to happen. I want to open a socket and keep it active and keep on sending the data on each button push conituosuly without recreating the socket each time.

The thing is im using hyperterminal and each time i have to connect again and again from hyperterminal to see the fersh data. I dont want this to happen. Once the socket is open wat ever data i send must come to the hyperterminal.

Please help me with this guys.. Its very urgent