Solved

Send data via TCP between two C# applications

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

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 63

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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