Solved

Send data via TCP between two C# applications

Posted on 2006-11-12
5
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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