Assuming that other computer is already to receive that tcp connection, check into the TcpClient object under System.Net.Sockets
The following is the code im using to send data from client to the server. The output of the entire program however is a series of x,y,z coordinates and other values but using the code im able to send only one instance of the output and not the entire series of outputs which are generated one after another. Please help me, i need to send the entire series of outputs generated one after another .
private void exportData(string person, DateTime time, double x, double y, double z,
double distance, double seconds)
{
// Write data to file: could modify this method to write to a database or other
// external system, filtering will work in the same way
StreamWriter file = (StreamWriter)files[person];
file.WriteLine("{0},{1},{2},{3},{4},{5}",
time.ToString("u"),x,y,z,distance,seconds);
Console.WriteLine("{0},{1},{2},{3},{4},{5},{6}",
person,time.ToString(),x.ToString("0.00"),y.ToStri ng("0.00"),z.ToString("0.00"),
distance.ToString("0.00"),seconds.ToString("0.00") );
IPEndPoint ipep = new IPEndPoint(
IPAddress.Parse("127.0.0.1"), 9050);
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
server.Connect(ipep);
}
catch (SocketException ex)
{
Console.WriteLine("Unable to connect to server.");
Console.WriteLine(ex.ToString());
return;
}
NetworkStream ns = new NetworkStream(server);
StreamReader sr = new StreamReader(ns);
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}",
person, time.ToString(), x.ToString("0.00"), y.ToString("0.00"), z.ToString("0.00"),
distance.ToString("0.00"), seconds.ToString("0.00"));
sw.Flush();
}