I am currently writing an application having a client server architecture.
The client is a Java android application
The server is a C# application.
The client will pull data from the server but in some cases push some data to the C# server as well.
The data that server needs to forward the clients is list of data structures (perhaps in the form of XML?), sometime binary data like files.
The client and server are communicating over a wireless network.
Speed and scalability is my top most priority in the design of the system,...
I have to write server as well as the client myself. I will be using sockets for communication.
I need your advise on the form of protocol I should use to exchange data between the Java client and C# server.
Should I write similar data structures (which seems redundant) in java and C# and serialize them ??
or should I exchange xml ??
I am not sure yet what is the best way to do it ..
Essentially there will be commands from client and server will respond with data
Please advise me on this topic the data communicated could be be as large as several gigs over wifi so speed is very important.
Well, there's always JSON. It should be well-supported on both ends and is easy for your server to generate and client to consume. Not sure it helps with your bandwidth concerns any...
I believe WCF might be approperiate for this, WCF uses soap so a Java implementation should work well. WCF also supports steaming, so transferring large files is possible, though I'm not sure if Java supports the streaming protocol.
As for performance, you will probably be limited by the speed of the device and not the protocol.
Have a look at this session from TechEd 2011: "My Customers Are Using iPhone/Android,But I'm a Microsoft Guy. Now What?"
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DPR304
It would probably be worth looking into MonoDroid if you want to share code between client and server (and if serialize/de-serialize makes sense).
As I don't know what you're building, I would advise you to read up on REST before you continue though. It should give you valuable pointers on how to create a nice API that can be easily consumed by various clients.
Related
I am looking for an open-source framework that can handle communication between my backend host and a WPF frontend client. The following are points I need to consider:
Client is a WPF desktop app, host is a C# console APP but can also run as Windows Service
Host can accept connection requests, client connects, but I still seek bi-direction communication capabilities.
The client and host are not in the same network (need to send messages over the internet)
Just one (possibly more but less than 10) client will connect to the host.
I like to be able to handle the following communication patterns: One-way message, two-way request/response, and streaming from host to client.
The content will consist of serialized POCOs/DTOs and serialized time series data. Each serialized DTO will be of approximately size 400 bytes, the serialized time series can be a lot larger, potentially several megabytes.
Some messages will be sent scheduled, meaning for example, the host sends a new DTO every second. (if the framework includes such scheduling mechanism then even better)
I like to be able to stream data to the client, such as a client that receives and then updates data on its GUI in real-time.
My question is: What might be the best C# based framework to handle this? (I run on .Net 4.5) I do not consider WCF because it seems way too thick and complex for what I try to handle. I also do not want to delve into web programming, so Rest/Soap type frameworks are not under consideration. I would be delighted if anyone could recommend a tcp/websocket based framework or similar that is light weight enough to potentially send messages a lot more frequently than just every second.
Thanks a lot in advance.
Any reason why you are not considering HTTP? It is just over TCP but you don't need to worry about firewalls and stuff, especially given the fact that you want to do this over internet. Self-hosted ASP.NET Web API can be a good candidate. Fire and forget and request/response can be accomplished fairly straight forward and for streaming it has PushStreamContent. ASP.NET Web API is light weight compared to WCF and is open source. Just a suggestion, that's all.
I ended up using ZeroMQ for full-duplex communication between WPF client and Server. It is lightweight, very fast and pretty reliable for my needs.
I am new to socket programming with C#. I am developing a client-server application with multiple clients. I am not quite sure how to form a communication between the server and its clients.
Is it a good idea for the clients to send keyword messages (i.e. 'string') that will invoke the server to do something?
Is it a good idea for the clients to send instances of certain classes (that I created) which need to be processed?
Is it a good idea to send/receive files (I am using XML) between the server and the clients?
I am sorry if my questions are naive as this is my first experience developing an application with a client-server architecture.
I found this link which has an example of such an application but I was wondering if anyone knew any other websites/books/tutorials with explanations.
If you create a modern c# application you seldom need to resort to plain sockets to create a client-server application. Instead you can create a WCF service. (Pick a tutorial and try).
Using a WCF service instead of plain sockets will save you from a lot of plumbing work with creating a protocol, parsing and that kind of stuff.
I am just learning c#, and am programming a Windows client that collects temperature data from the computer and needs to send it to a remote linux mySQL Database.
I was going to program it directly in the c# client, but I want to learn more ways to do this and gain experience. And programming it directly would be less secure and most likely require an extra connector.
Can any of you advise me of other ways, or ways you would do this?
Any way to program a C# program that acts as a web-service on my linux mySQL Server? Where should I look/search to learn more about this. Is it called something special? Or maybe its not done in C#?
Should I program a php script that accepts HTTP SEND/GET requests from my C# Desktop client?
Any other way?
What way is most 'professional' in the real world? Trying to learn on my own! :D
FORMAT:
Windows Desktop: client programmed in C# That retrieves temp data and needs to send to server
Linux Server: Runs Apache and mySQL Server with a database already setup. Closed to outside Connections
My advice is to set up a web service to communicate with your windows client. Directly connecting to mysql server is ok if they both resident in a same lan, but if not, for example your windows client is running on some laptop travelling everywhere or even the mysql server permits local incoming connection only, your should set up a web service. Also the http connection can usually go through firewalls while connections over other ports are blocked.
php is a good way to do this. Since you are learning c#, you may want to use c# to do the server side programming as well, so why not give a try of mono?
Directly exposing a MySQL Server to the internet is strongly dicouraged, Additionally this gives you a rather coarse-grained set of access rights, that might not be enough for your application, so running some sort of server app is the right way to go.
With mono you can run a lot of .Net (and thus C#) based code on a Linux server just fine. Rule of thumb is: If it doesn't have a Winforms GUI and no P/Invoke it will work just fine. Ofcourse this needs mono on the server, which is not given on most commercial hosts.
Running the server in PHP makes it a lot more portable, but has a performance overhead. Additionally it doesn't allow for some of your busines logic objects to be implemented in a DLL assembly and used on both sides.
As for the protocol: Chose your poison. Rule of thumb again is, that predefined protocols such as SOAP tend to need a bit more work (and more learning in the first go), but on the long term tend to be more robust.
For your special use-case I'd personally go with a quick PHP based solution where the protocol is just a simple GET with a few parameters, one being the temperature(s) and the others authenticating the client.
If the temperature sensor generates events, then I would 'push' the data from the Windows box to the Linux box - this will save the latter checking often and finding no updates. However if you are just taking temperature samples, I would 'pull' the data from the Linux machine. Either way, if you want to use HTTP you will need a web service on either side.
Alternatively, you could just connect to your MySQL database remotely from C#, and write the data directly (no web service would then be required). That might be the quickest way to get this working.
The 'which is professional' question is subjective - all three options above are fine. Just make the code clear and concise :)
I'm about to start to develop and application in C# but I realized that I haven't the enough knowledge to develop it yet :S.
The thing's that I need to find out a way to let the Web server comunicate with my application, i.e., in short, is there a way to let the web server (not the Client which is the trivial case) send a messege to a Client application?
I know that I way to solve it's to make Client applications periodically send messages to the web server but that's not what I want 'cause polling generates overhead
Sorry about my english! I'm not a native speaker.
Thanks in advance!
Generally this type of interaction is achieved with Comet or WebSockets - I'm not sure how your app will be communicating with the server, but I would bet you can do what you're trying to do using one of those.
You could implement a WCF service in your client that could listen for a connection from the server (or anything else). The server can communicate with the client as easy as calling the API.
Getting started with WCF is really easy using the wizards in VS.
Here is a link that talks about using WCF with ASP, but it can be used outside of asp as well.
It seems like you meant "push" messaging, the challenge around this is for the server to keep track of the lost of clients and manage who should recieve which message.
If you want to get it done with minimal overhead you can check out the Amazon Simple Notification Service.
SNS is a cloud-based messaging and notification service hosted and managed for you, SNS is based on a topic/subscriber model and you set it up via a few simple API calls, it is metered but quite inexpensive for the most part.
edit: For C# Libraries and frameworks to do it yourself, I am not an expert in the C# world so I think other answerers will know it better.
Disclosure: I work at amazon so I am naturally inclined to like their product
I'm writing a simple accounting program consists of several C# winform clients and a java server app that read/write data into a database. One of the requirement is that all C# clients should receive updates from the server. For example, if user a create a new invoice from his C# client, other users should see this new invoice from their client.
My experience is mainly on web development and I don't know what's the best way to fulfill this requirement with C#s client and Java servlet server.
My initial though is to run ActiveMQ with Glassfish and use messaging pub/sub method so that updates can be pushed to C# client. I will create different topics like newInvoice, cancelInvoice, etc in order to differentiate the message type. Each message will simply contains the object encoded in JSON.
But it seems to me that this involves quite a lot of work. Given that my user base is very small ( just 3 or 4 concurrent user), it seems to me that there should be some simpler solutions. (I'm not familiar socket programming :) )
I know this is a client-server programming 101 questions but would be great if any experienced programmer can point me to some simple solutions.
The simplest approach here is often to simply use a poll - i.e. have the clients query for data every (your time interval). That avoids a whole family of issues (firewalls, security, line-of-sight, resolution, client-tracking, etc).
With WCF, you can have callbacks on duplex channels (allowing the server to actively send a message to clients), but this is more complex. I value simplicity, so I usually just poll.
Tricks that help here are designing the system to have an inbuilt mechanism for querying "changes since x" - for example, an audit table, perhaps fed by database triggers. The exact details vary per project, of course.
Another option that you might want to look at is ADO.NET Sync Services; this does much of what you ask for, for keeping a local copy of the database up to date with the server - but has a few complexities of its own. This is available (IIRC) in the "Local Database Cache" VS template.
Rather than pushing information from the server to 1:N Clients, would it not be easier to have the clients Poll the server for updates every so often ? Or when the client launches and creates a connection to the server, the server could dynamically generate a new Message Queue for that Client Connection, which the client could then poll for updates?
There are several push technologies available to you, like ActiveMQ (as you mentioned), or XMPP. But if you only have 3 or 4 clients to concern yourself with, polling would be the simplest solution. It doesn't scale well, but that isn't really a concern in your case, unless your server is an 8086 or something 8-)
You may want to take a look at StreamHub Push Server - its a popular Comet server written in Java that has a .NET Client SDK for receiving updates from the server in C#. It also has a Java Client SDK and the usual Ajax/Comet web browser support giving you more flexibility in the future to push data to web, Java and C# clients.