Communication type between applications [duplicate] - c#

This question already has answers here:
Can I communicate between Java and C# using just sockets?
(2 answers)
Closed 9 years ago.
I am about to develop a server using the Java language for a game.
The game is written in C#, and they are going to communicate through sockets.
The only way I can come up with is using JSON.
What is the proper way to do this?

The proper way is to have either a RESTful or a SOAP-based web service on the server
side and the client to call it. This is also going through sockets on the lowest level.
If you want, you can implement socket-based communication yourself (no REST/SOAP)
but I would not recommend it as it will make your job more difficult and error-prone.
But on the other hand, this may be more efficient, if you implement it well.
So you have many options, it all depends on the exact needs/requirements.

If you want to communicate properly your applications, I suggest you think about a multi-threaded server, in which every worker thread should poll the open socket and deal with the request, and you should write all this with kind of low-level I/O and multi-threading APIs.
Though it is possible to do it, I must recommend you to leave your communications to an application server, for example a Tomcat server or something similar. There you can deploy your java server as a web application implementing a REST or SOAP based webservice.
This way, you are covered with a production-strength server doing your communications duty for you, and can focus on writing a standard webservice client in C# (I admit I can be of little or no help at all in C#, but I guess someone here will be glad to help you there).

If your looking for a convenient API / library to communicate between apps, you may want to consider zeroMQ.
For webserver-client models. You may want to consider implementing a HTTP REST/SOAP interface.

Related

How to communicate between two C# applications(sending messages and receiving messages)?

As per my knowledge, I knew that messages can posted from one application to other application using "SendMessage" or "PostMessage".
I tried using SignalR to communicate b/w the applications. The problem here i found was server should be launched as a console application and clients will be my winforms. Ideally I don't want to show this console application as it seems to be weird for the user. If there is any work around for this approach please suggest.
After signalR I came across EventAggregrator in c#. Can we use EventAggregrator to communicate b/w two different C# applications? If yes could some one give an example on how to do this.
Until a few years ago, Socket class was the right way to do this. There are probably more modern, robust and easier ways to achieve the same result nowadays, but you may want to look at what's under the hood.
Socket class on MSDN:
https://msdn.microsoft.com/it-it/library/system.net.sockets.socket%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Client-server example on CodeProject:
https://www.codeproject.com/articles/463947/working-with-sockets-in-csharp

Client Server architecture using python and C#

I am trying an application to write an application on which I have used a client/server architecture. The client side is developed using .NET\C# and the server side is developed on python. To communicate the both sides, I used first tcp/ip socket; so i put my python's methods on a loop then I ask each time from my c# application to run an method. This idea is very bad as it require to cover all use cases that can be happening on network or something like that. After a work of search, I have found three technologies that can answer a client/server architecture which are RPC, RMI and WCF. RMI a java oriented solution so it is rejected. So, my question here is: does RPC and WCF support multi programming languages (interoperability) especially betwenn C# and python?
I'm not sure I completely understand your use case, but I would suggest having a look at a REST API approach if you need to have .Net talk to Python, or vice versa.
An alternative is using Pyro4 to expose Python objects on your Python server side and talking to them via the C# client library provided by Pyrolite. This mostly hides any networking specific programming details.

How do I implement a proxy-like TCP/IP server in C#?

I want to create a simple application in C# that sits between an existing TCP client and server, both legacy systems. Most of the time the application will simply pass messages from the client to the server and back again without modification. In one, maybe two cases, when it sees certain data from the client, it will modify this data slightly before passing it onto the server. It will not change the length of the data. It will not change the response from the server. How do I implement this in C#?
After much Googling, I found some suggestions, (some being an understatement!). There seems to be a multitude of way to implement a socket server in C# and no single, standard way, For example:
Kerry Jiang's SuperSocket.
Craig Baird's Code Project C# TCP Server.
Microsoft's own Asynchronous Server/Client Socket examples.
StackOverflow's own discussion on High performance TCP server in C#.
Any many, many more.
All in all quite a bewildering amount of information! It all seems overly complicated and total overkill for my use. I first thought of doing this in WCF, where all the underlying complexity is handled for me but apparently it's not possible (or very difficult) to do in WCF. Is there some way to implement what I want without going into all this complexity? Any 3rd party library or component that would simplify this implementation? Alternatively, maybe there is a hardware device that would allow me to this? Over to you.

Long polling with an iOS client app and a C# server

I'm writing a web server app for the first time, and I'm not really sure that I know what I'm doing.
Basically I have some server side C# code and a native iOS app. I need to be able to push updates from the server to the app. The method which we have decided to use is Long Polling, and I can see three ways of doing this:
1) Writing my own web server in C# - not neccesarily tempting as it requires re-inventing the wheel
2) Using WCF - I've seen a few articles about how to implement long polling over WCF, but the tutorials that I've seen all seem to use clients which are implemented in .NET WCF which is not applicable for me as I need to use an iOS app.
3) Something else, possibly using IIS - I don't really know where to begin with this option.
Can anyone recommend a good tutorial, or exemplar project which uses standard HTTP to implement long polling with a C# server? So long as it's using standard HTTP, I'm confident with the iOS side of things.
Obviously if there's an even neater way of doing things then I'm all ears as well.
I would highly recommend that you investigate SignalR which allows you to achieve exactly what you are after. There are many iOS tutorials as well as HTML / JavaScript and of course C#.
One of the benefits of SignalR is that it tries to use the best technology available on the various devices and down-grades until it works. So, will start with Web Sockets for example and fail down to long-polling if nothing better is available.

java server <-> c# + javascript + java + * clients

What "technology" would you suggest to exchange some kind of messages between a Java server and several clients written in C#, Javascript and Java?
The background story:
In our current project we're trying to build a generic UI backend in Java (running on the server) which is then "bridged" into several UI frontends by means of different UI adaptors (running on the client, the server, or both). While our server technology will always be Java, there will be C# (Silverlight), JavaScript and Java clients. Maybe even more in the future (different Smartphones, Tablets).
The UI backend and UI frontends communicate through a bunch of more or less simple messages (mostly name/value-pairs) each of which encapsulates a specific property/state/data change on the client or server respectively. Within a single request cycle, several such simple messages are aggregated into one big message which is then passed from backend to frontend or vice versa. At the moment sending and receiving messages is done at a single entry point on the client as well as on the server. So there are no server methods exposed as WebService etc. - simply because this would most definitely be to slow in our case.
Our current prototype consists solely of a Java server, a Java Desktop Client (Swing) and a Java Web Client (Vaadin). The message exchanged between backend and frontend is effectively a list of POJOs (each representing a specific "change") serialized/deserialized to/from XML. So far, so good.
Now C# and Javascript come to the table. Since we want to work with some kind of object in each technology, we thought it would be a good idea to specify the messages/changes/pojos in some kind of abstract language and then generate objects for each target language. At some point these objects could then be serialized/deserialized and sent over the wire (probably via http/s). For this purpose we thought of Google's protocol buffers or Thrift. What do you think?
For the moment our synchronous request-response-cycle is enough but we will need asynchronous request-response or server-push respectively pretty soon. That's why we thought of using something like ActiveMQ straight away. What do you think? Too much? If not, how can we accomplish the object generation mentioned above (xsd, jaxb, ? for js)? Are there better ways? I've never used ActiveMQ but according to the website it should be possible with Java, C# (Spring.NET) and somehow with Javascript (STOMP) too. However, this seems pretty complex to me...
Any tips, hints, experiences or comments about this or related topics would be really helpful.
Thank you in advance.
I would recommend using webservices. The WSDL language defines objects and messages of your protocol in abstract form. Most modern languages like Java and C# have tools for converting WSDL to native types and libraries for handling I/O.
For the last two years i have been involved in building a similar system: backend for our project is c#, java and bunch of other languages, frontend is phone clients for ios, android, symbian, all the common webbrowsers and even windows desktop apps.
For all these services we use JSON, since it seems to be most widely supported format across all languages and platforms, it decodes fairly fast on the clients compared to xml based solution (esp. webbrowsers/javascript) and it has a pretty low overhead that compresses extremely well which is great for clients that lack bandwidth.

Categories

Resources