Communicating between two computers with c#

c, c#, sockets

Solution

UPDATE: 5 years later

I would use gRPC with protbuf serialisation now. This would allow you to use different languages for the client and server. ProtoBuf is also full-compatible (supports both backwards and forward compatibility). Here is the _"Getting started") documentation: https://grpc.io/docs/quickstart/csharp.html

I think the best solution for you is using WCF service. http://msdn.microsoft.com/en-us/library/ms734691(v=vs.110).aspx Here is a short example from the above link:

// Define a service contract.
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
    [OperationContract]
    double Add(double n1, double n2);
    // Other methods are not shown here.
}

and the client

// Create a client object with the given client endpoint configuration.
CalculatorClient calcClient = new CalculatorClient("CalculatorEndpoint"));
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = calcClient.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

The whole point is that you have a contract (interface) and a service (class) which implements this interface. Then when this service is hosted in web, forms or console app you can add a reference to the service from another app it doesn't matter what - there are variety of transports (bindings) available. Here is a link to getting started section on MSDN http://msdn.microsoft.com/en-us/library/ms731067(v=vs.110).aspx

Problem

So, I am trying to build some kind of remote control application with C# but I don't know anything about Socket Programming. I did a lot of search on it but I couldn't find what I was looking for. The only thing I need is to communicate between two computers over the internet and I just need a way to be able to send and receive a simple String variable like "robot:move" but I can't figure out how and I'd be more than happy if someone could help me. P.S. I haven't started the project yet so it doesn't matter if it's windows form or console application Thanks in Advance Update : Thanks for the help I learned how to use WCF and I managed to create my desired application but unfortunately it only works locally and I don't have static IP address or Windows/IIS hosting to host it over the internet. The only thing I have is a Linux/Apache host and I tried mono, it was a no go. So I wanted to know if there are any different solutions to my problem. P.S. Is there another programming language like C or JAVA that makes this possible? If so can you give me a link about how to do it?

Original source