473,685 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send data as tcp stream using C#

44 New Member
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 10660
7,872 Recognized Expert Expert
Assuming that other computer is already to receive that tcp connection, check into the TcpClient object under System.Net.Sock ets
May 25 '07 #2
44 New Member
Assuming that other computer is already to receive that tcp connection, check into the TcpClient object under System.Net.Sock ets

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(stri ng 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)f iles[person];
file.WriteLine( "{0},{1},{2},{3 },{4},{5}",
time.ToString(" u"),x,y,z,dista nce,seconds);
Console.WriteLi ne("{0},{1},{2} ,{3},{4},{5},{6 }",
person,time.ToS tring(),x.ToStr ing("0.00"),y.T oString("0.00") ,z.ToString("0. 00"),
distance.ToStri ng("0.00"),seco nds.ToString("0 .00"));

IPEndPoint ipep = new IPEndPoint(
IPAddress.Parse ("" ), 9050);

Socket server = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);

server.Connect( ipep);
catch (SocketExceptio n ex)
Console.WriteLi ne("Unable to connect to server.");
Console.WriteLi ne(ex.ToString( ));

NetworkStream ns = new NetworkStream(s erver);
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.0 0"), y.ToString("0.0 0"), z.ToString("0.0 0"),
distance.ToStri ng("0.00"), seconds.ToStrin g("0.00"));

Jun 4 '07 #3
7,872 Recognized Expert Expert
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
44 New Member
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.0 0"), y.ToString("0.0 0"), z.ToString("0.0 0"),
distance.ToStri ng("0.00"), seconds.ToStrin g("0.00"));
Jun 10 '07 #5
44 New Member
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

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 But the problem occures when i want to send a data with & sign (i.e: Firm=F&B). I try to solve this problem with using boundary, but i failed. Any idea!?
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, to HIS port 8801. This means that I need to bind my sender socket to (myaddress,8801), use it for the send, then shut it down and close it. Then I want to wait, say 30 seconds, and do it all over again. Naturally, the socket's ReuseAddress...
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 name=fileupload</input> </form>
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 to do this in my own time and then hopefully teach them how to do it. I have installed IIS on my machine and have followed a few web
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 int(float(a)) except: return 0 The reason for this is the quality of the data from the huge variety of
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 data. I tried sending using GET request and GET is working fine. Here is code snippet function postRequest() { \n\ if(window.ActiveXObject) \n\ xmlHTTPObj = new ActiveXObject('Microsoft.XMLHTTP'); \n\ else if (window.XMLHttpRequest) \n\
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 Sub SendData(ByVal IpAdd As String, ByVal sData As String) Dim myIpAdd As System.Net.IPAddress Dim myPort As Integer = 4003 'Convert data String to Byte()
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 test like this, while 1: x=sys.stdin.read(100) if x: print x
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 sendsd the data to the webpage and receives the response to that particular values from the webpage. I am trying to use httpwebrequest for this purpose, but I am receiving errors, kindly let me know where I am going wrong. When I llok at the...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.