Solved

Send data via TCP between two C# applications

Posted on 2006-11-12
5
433 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now