Solved

Send data via TCP between two C# applications

Posted on 2006-11-12
5
435 Views
Last Modified: 2008-02-01
Hi,

Could somebody provide sample code for sending data between two .NET applications using TCP?

i.e. in app one:

string foo="data on a machine";


In app two, on a separate box, across a LAN (thus TCP)... how could I recover the value of "foo" from app one and assign what is returned to local variables for processing ?


Thanks!


 
0
Comment
Question by:James_15
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17925378
Hi James_15;

You can use the .Net Remoting technology to do this. Here is a link to a article with sample code explaining how it works called:

    .NET Remoting with an easy example

http://www.codeproject.com/csharp/Net_Remoting.asp


Fernando
0
 

Author Comment

by:James_15
ID: 18014323
Hi Fernando

Apologies for the delay in replying to your message - I have been on holiday.


Could you provide a code sample that would:

1. Create a server using TCP waiting for data
2. Create a client that can send data to the server in 1.
3. The server application does something with the data - e.g. push the information into a stack/queue ready for processing?


Thanks,

James
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 18015614
Hi James_15;

Please download the the files from this site http://www.codeproject.com/csharp/Net_Remoting.asp, Download source files - 16.6 Kb.

Compile the RemoteableObjects and compile run the server and client projects. In the server project you may have to delete the reference to the RemoteableObjects and re-create the reference because the author may have place the project in a different path then you did.

The sever is always listening to the network on TCP.
The client sends information to the server.
The server does something to the data, in this case displays the info to a text box.

The program is set up to work on a single computer but if you want to use it across a network then change the following lines in the code.

The Client:
remoteObject = (MyRemotableObject) Activator.GetObject(typeof(MyRemotableObject),"tcp://localhost:8080/HelloWorld");

Chance the word localhost to the name of the host on where the server is. Also if you need to use a different channel then 8080 then change it to reflect the channel you want to use.

Fernando
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question