P2P app chat with WCF - c#

I followed the example on this link.
It worked pretty well - but it worked like a Chat Room.
I dont know how to just send and get message between just 2 clients.
Can someone give me some advices to do that?
Thank you for reading.

As far as I know you cant have only clients. You need to have both, a client and a server.
If you are trying to make a chat program with only 2 users, one of the users needs to act as a server and the other as the client. You only need to put a constraint on the server to allow only one client.

Related

Multi-Client Server communication when server is offline

So I want to create a Multi-Client/Server application. I know multiple clients can connect through one port, and I want to allow for the messages to be stored in a list when the server is "offline".
I'm having trouble finding information online to help me understand how the server can tell the difference between the multiple clients on the port. For example, if a 2 clients send messages to the server while it is offline and I store them in a list, how would I be able to tell the server that this message came from this client first so answer that, and then this message came from this client next?
Is there any information online on an easy way to achieve this? Any help would be greatly appreciated.
Sorry, I didn't make it very clear. I'll try again! Ok basically I want like a middleware between them so that the clients contact the middleware with the message, the middleware checks if the server is online and if so it sends it on, otherwise it will store the message(s) until the server is connected again. Does this make more sense? I'm not great at explaining myself, sorry again!
There seems to be some confusion of concepts here. When client are not connected they obviously can't send anything to the server and also don't have a port. Conversely, when the server is running and clients connect to it, the server has an object for each connection, representing each client.

Can you send data to clients from a WCF service without the clients having to call the service?

Say I want to write a peer to peer chat application. And I use a WCF service as the server that the clients 'log in' to so that they can find each other's ip addresses and ports.
Well, say also I have a textbox in my client application that display all users that are online. Everytime users log in or out I want to update this 'Who's online' textbox so that only the currently online users are shown.
So the server needs to send information out to all clients once a user logs in or out. But it seems WCF can only send data when responding to requests....
Am I missing something here, is WCF able to handle this situation?
There are several approaches to this problem, these would probably be the most common:
Use publish/subscribe, like in this good article.
Keep all the currently logged users in a storage - a database or whatever you'd prefer, and query it from the users' side.
I think you need a duplexing service.

C# Simple DataSocket Example Needed

I am new to C# Socket programming. I am trying to build a simplistic application that can detect when a client application connects to the server application.
When connected, I want to send 1 piece of information to the server and receive 1 response back (confirmation).
Afterwards, I just want to know when the connection is broke. Within my application, I do not have to know instantly when the connection is broken, just within the timeout if fine.
Can someone please help me understand what I need to do to accomplish this. Sample source code would be nice, again I am a novice programmer and this topic is way above my head.
I would need help with the client app and server app.
Thanks in advance!
Jorel
I would not begin with sockets if I were a novice programmer. It's not an easy subject to start with, and you need to know more than just how to send a piece of information. You need to know how the protocols work too and how do deal with their way of send/receiving information.
I would recommend you to use wcf instead, since WCF takes care of all lower level details for you. You will just need to know how to send and receive information.

C#, WCF, want to make a chat application, what binding should I use? maybe some examples?

I am looking forward to make a sort of a chat application using C# and WCF, yet before I start I wanted to clear a few things, so that I don't get carried in the wrong direction. :)
the application should be able to both make event ( send messages ) and listen to events ( receive messages ), therefor if I understand it right, the application should be both the client and the server at once?
what binding should I use? If I understand right, basicHttp binding hard to configure and is used when a WCF app needs to connect to non-WCF app? While for connecting two WCF apps its better to use NetTcpBinding?
how would this applications find each other, considering that they are running on different machines? should there be a central server, to which the app would connect first, saying "I'm user123, my IP is that and that, I'm free for chat" and look for other user IP addresses there? Or is there some other ways for apps to find each other without the central server?
maybe you could direct me to some examples or tutorials on this topic? ( tried googling, no luck ).
Thanks! :)
If your peers (machine that can operate as a client & server) are going to be behind NATs/firewalls then you will have a very very tough time building a chat application using WCF. If the peers will all be on the same network WCF is workable.
To write a chat application from scratch using WCF you will be re-inventing the wheel. Why not employ an existing protocol that's been designed precisely for the purpose such as XMPP. There are XMPP libraries around for .Net. You will need a central server but if you use XMPP you could feasibly piggyback onto one of the many existing free servers.
You can use netPeerTcpBinding.
See also:
http://blogs.interknowlogy.com/2009/08/05/building-a-really-simple-wcf-p2p-application/
http://msdn.microsoft.com/en-us/library/bb690929(v=vs.90).aspx
http://www.codeproject.com/KB/WCF/Chat_application_using_WC.aspx
There is no right and wrong answer to your question - it all depends on what you require. You then can choose the best architecture for your needs, and then the best technology for that architecture.
There are two things to consider - how will users find people to chat to, and then once they have found someone - how do the applications connect to each other.
For users to find each other, you either need to connect to a central server, which will then show a list of all connected users, or users need to enter the IP address of the person they want to chat to. Note that some firewalls will block incoming connections in this second case, so this may not be feasible in some cases.
Next, once you have found the person you wish to chat to, you need to decide whether messages will route directly to the other user, or if you want to continue to go through a central server.
If you choose to go through a central server, then your application will be functioning as a client, and will therefore pass through firewalls without a problem. However if you connect directly to the other user, both copies of the application will be acting as a client and a server (P2P topology), and therefore firewalls may be an issue. Having said that, you could designate one of the applications to be a server, with the other acting as a client, in which case only the server side needs to worry about the firewall.
Without knowing exactly what you are trying to achieve, it is hard to recommend which architecture will work best for you.

Sending & Receiving "Nudges" via tcp?

I'm tyring to add a feature to my app that sends a nudge to all users of my program (family members inside the house), and when they receive the nudge the window of my app on their computer shakes for a second...
Can somebody please suggest how i'd have to go about this? I've never worked with tcp/ip before.. Is this what I should use, or is there something better?
I have tried to come up with my own solution however none of the samples ever work. So I thought maybe the people on SO might know of other ways?
Thank you :)
If this is just an "in-house" (pardon the pun) application, and you're all on the same network, you might consider sending a UDP broadcast packet. Each instance of your application could listen for a packet on a particular port, and when the correct one is received do the window shake thing.
You might consider UDP for this. Since you can broadcast/multicast via UDP it may be more suitable for this sort of application. There are downsides - UDP transmission is not reliable or guaranteed in the same way as TCP.
I'd go with a good XMPP Library. Maybe Jabber-Net?
You'll also have the added bonus of being able to connect to Google Chat and now Facebook chat later.
You haven't specified if presence in your case requires a server or not. If it is client/server oriented, using XMPP gives you the server side for "free" as a bonus.

Categories

Resources