Solved

Send data via TCP between two C# applications

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

27 Experts available now in Live!

Get 1:1 Help Now