473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to send data as tcp stream using C#

I have a C# program which outputs x,y,z coorditate values of objects tracked by sensors connected to the system. These output values are stored as a text file.

All i need to do is, send the output (x,y,z) of the program directly as a tcp stream so that it can be received by another computer on the network.

It would be nice if someone can help me on how to send tcp stream using C#.
May 25 '07 #1
5 10650
Plater
7,872 Expert 4TB
Assuming that other computer is already to receive that tcp connection, check into the TcpClient object under System.Net.Sockets
May 25 '07 #2
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();

}
Jun 4 '07 #3
Plater
7,872 Expert 4TB
Well, I don't see any looping mechanism there and you open a new socket every call there.
(PS: Don't forget to close all your files and sockets when you're done with them)
Jun 5 '07 #4
I have finally sent data from client to server using tcp connection. Now i need to send the same data using udp.

How do i replace the following code when implementing in udp ?.

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();
Jun 10 '07 #5
I have established connection between udp client and server. Now i need to send the data from client to server. How do i do that ?. The data consists of x,y,z coordinate values and other parameters which are generated continuosly and need to be sent at runtime.
Jun 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
2
by: Cuong.Tong | last post by:
Greeting, Can anyone give me some hints about parsing the mulitpart/form-data stream? I have a form looks something like this <form action="process.dll> <input type=file...
5
by: trig | last post by:
Please help! I am an ICT teacher at a secondary school and my year 12 (AS Level) group need to create a website where data can be sent from a form to a Microsoft Access database. I am trying...
4
by: Doug Gray | last post by:
Folks, I am looking for a fast but most importantly a bullet proof method to pass and NMEA data stream (GPS output) ascii numeric strings. The best I can offer is: def fint(a): try: return...
2
by: ajaxcoder | last post by:
Hi In my project i had a login form and i am trying to send the username and password to the server for authentication using xmlHttpRequest. Hence i am using POST request but i am unable to send...
3
by: romcab | last post by:
Hi guys, Just want to ask how can I send data serially? I have here a sample code but I use sockets and tcpclient class but I'm wondering how to do it using serial cable.Any idea? Private...
6
by: sapsi | last post by:
Hello, I am using HadoopStreaming using a BinaryInputStream. What this basically does is send a stream of bytes ( the java type is : private byte bytes) to my python program. I have done a...
5
sid0404
by: sid0404 | last post by:
Hi I am new to the visualstudio.net I am trying to develop an application which requires me to send data to a HTML webpage - http://patft.uspto.gov/netahtml/PTO/search-bool.html and the user...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.