wcf server sending data to one client - c#

my problem is that i am trying to write a program that sends data to clients via wcf.
i have read a lot about it and finally i saw this topic in code project: http://www.codeproject.com/Articles/34333/Topic-based-publish-subscribe-design-pattern-imp
i have implemented it so it will be good to my needs.
the problems are:
i have multiple clients and there is some messages that i need to notify only one client and not all of them.
sometimes i want my client to receive a message from the server,do something and then reply another message to the server
thanks ahead for the help

Set an id for your clients. And then just include id (or id collection) into your messages, so clients can filter messages.
I guess you can develop your client so it can be both publisher and subscriber? Not sure what is the problem here

Related

How TCP server knows where to send message? (client A or client B?)

Tcp server implemented
Tcp client implemented
server started
client A connect
client B connect
client C connect
client A send message to server(but he wants to send to client B or C or to all of them)
E.g.: Let's say that...
Server needs to send this message to client B
How client A will send the message so that server will know that A want to
send this message to B or C etc..
Should client A together with the message to send the ID let's say of client B so server extract ID and after somehow knows that will forward that message to client B?
..Or is completely wrong how i think chat app works?
Should each client work as a server too? and when client wants to talk with client B the same logic applies?
I have searched online for examples but most of then rely on simple server and one client.
I don't need code, just the idea so i can understand how this works.
Any help appreciated, thanks!
Check out https://github.com/microsoft/Build-Mobile-App-with-Chat/blob/master/02%20Tutorial%20Guide.md
There is code and logic for non TCP chat using server push technologies and service bus to accept messages and deliver them.
For TCP, same principles apply. Receive the message on a certain topic, add it to some queue or a topic (better for chatrooms with multiple people) and deliver from a background job to all people interested on the topic.
You will of course need some kind of persistence layer to store messages and track delivery, history, likes and the sort.

Grpc - send message from one client to another client that is connected to the same server

Is it possible to send message from one client to another client that is connected to the same server?
I want send data from one client to server Then send to specific client. I think I need to get client ID but I dont know how to get this id and how to send this message to that client from server.
I have a sample here. This is a chat server-client application. Multiple clients can connect to the server. When a client writes a message, the server simply broadcasts it for all clients who are receiving server stream RPC.
https://github.com/cactuaroid/GrpcWpfSample
See these server side implementation. When a client calls Subscribe(), it awaits m_chatService.Added event. When a client calls Write(), it raises the event and event args ChatLog is written on responseStream.
https://github.com/cactuaroid/GrpcWpfSample/blob/f6e8c4b2493c23cdcbaffeca29b5bb6705fbe95c/GrpcWpfSample.Server/Grpc/ChatServiceGrpcServer.cs
https://github.com/cactuaroid/GrpcWpfSample/blob/f6e8c4b2493c23cdcbaffeca29b5bb6705fbe95c/GrpcWpfSample.Server/Model/ChatService.cs
You can add your logic such as specifying channel name to subscribe/write, or define OpenChannel(string password) to be called by client at the first time so that server can bind the client IP address to the channel, whatever as you like.
There's no special gRPC feature that would allow you to do this (all RPC are between a server and a client, there's no "broadcast" or "selective broadcast" feature to reach out to other clients connected to the same server.
The logic you want is something that can definitely be implemented and but details of such solution depend on your need. A naive approach that might work is e.g. this:
each client opens a bidi-streaming call to the server
server keeps a directory of connected clients
once server receives a message from a client, it selects which client it should forward to based on the directory.
server forwards the message to a client.
Needless to say this setup feels a bit complicated (you're basically implementing your own network protocol on top of gRPC), so even though it might be just the right thing for you to do, it would make sense to think about how to simplify the protocol so that you can use features directly supported by gRPC.

Best approach for Java web service sending data to C# client

Here’s our architecture:
JIRA webhook sends messages to a Java Jersey REST service when issues are assigned.
C# client application registers the username/host machine combo with the Java web service when a user logs into the machine
When the web service receives a message from JIRA, it finds the assignee username and sends the required data to the C# client app on the host machine(s) the user is logged into.
I’ve thought of a couple approaches to solve the web service to client message.
My first is opening a TCP port on the client and having the service send each message directly to it. This is the most straight-forward approach but makes the client a little heavy in that it maintains the list of user assigned ticket data that they can then manipulate (acknowledge or remove).
The other is having the service maintain the data model and the client requests data periodically. This makes the client simpler but then I’d have to implement a polling interval to grab data, and add some POST methods for acknowledging and removing data from the user’s list.
I was looking into different ways to have the client register a channel with the service, like ServiceStackEvents, but I can’t see a way to make that work with a C# client and Java service. Something like that would be perfect. A way for the service to send callbacks or event messages to a client based on a user filter.
If someone has some suggestions or knows of an API to help with this, please post a link so I can dig into it. The POSTs are all working swimmingly, it’s just getting the data back to the clients that I’m struggling with the best approach.
Thanks!
Client polling is not a terrible solution.
But if you want a firewall and proxy friendly duplex protocol, check out WebSockets https://en.m.wikipedia.org/wiki/WebSocket.

Detect missed messages/missed actions on messages on reconnect

I am using SignalR in my application to send messages to different users in a group.
We have the capability that messages can be added/edited or deleted and the same action is sent to all the users in that group via SignalR hub.
All that is working fine.
The issues is one could miss other people actions (message add/edit/delete) which happened during the time when his connection was lost/ internet disconnected or his laptop/machine was off.
After getting connection back or opening the laptop again that user must receive all those missed messages, missed actions which occurred during the time he was offline.
We are storing all clients (client id) of all users in database.
Can anyone give the pointers how to do that?
One solution can be to poll last message id (which has come to ui) to server check if any new message is there but that won't serve the purpose because message could have been edited/deleted at server from other user.
I have already gone through following links
Can SignalR handle missed messages?
Can a SignalR message loss be detected server side?
How to do guaranteed message delivery with SignalR?
Signalr client to retrieve missed messages on reconnect
https://github.com/JabbR/JabbR/issues/699
but none of them is covering the aspect for the entire history which happened during the time user was offline.
For example if you are disconnected in Skype and comes back say after few hrs it pulls all the history of all actions (message added/edited/deleted) that occurred during that time and update it to end user
Since SignalR doesn't povide any guarantees of message delivery - one should solve this by himself.
There are several approaches:
The first is to use message queues (ex: RabbitMQ).
This is the most efficient way to guarantee that message is delivered to client.
But in your case you'll need to combine message queueng with pub/sub way of communication. That can be tricky.
The second way is described in the answer to one of SO posts, that you referenced: Can SignalR handle missed messages?.
Don't send data over signalr, only notifications; then get the data update from the server.
That is my favourite way of client-server notification/update scheme. And I'd choose it in your case.
One solution can be to poll last message id (which has come to ui) to server check if any new message is there but that won't serve the purpose because message could have been edited/deleted at server from other user.
To overcome this you can poll not the last message, but history of actions made in conversation (add/update/delete message actions) since last updated and apply it on the client side.

pub/sub technique to "guarantee" messages are delivered to all subscribers

i am developing an android application and i want to broadcast some message to all my clients with RabbitMQ. is there any way wiht RabbitMQ, that supports offline clients - by offline clients I mean that if i have server submitting messages to the clients,and some clients are unreachable,the client will receive messages after it gets connected again.
Is there some open source solution for that? It seems that rabbitMQ does not do this,i might be wrong tho.
Any help would be appreciated.
You can create a unique queue for each client. Bind those queues to a common exchange. Then every time your client will come online it will create a connection to rabbit (earlier defined queue) and will consume messages.
I think you would better benefit from topic exchange (https://www.rabbitmq.com/tutorials/tutorial-five-python.html)
And bind them to a common exchange with desired routing keys.

Categories

Resources