2

Possible Duplicate:
multi client/server chat program in c#?

I've been trying for some time to build a simple client-server chat, and I keep finding that there are a number of different ways.

I was just curious as to what the most correct way would be.

The first involves creating a new socket, binding it to a specific port and any IP Address, then listening for new connections (and that's as far as the tutorial leads). The next involves using a TcpListener to listen on a specific port (though it issues a warning saying that its deprecated, and I must include an IP address), it then waits for a new TCP connection, then creates either a new hashtable or new list to store the TcpClient(s). And that's all server side. Client side its pretty much the same, always trying to connect to the server.

So, what's the best way to go about building one? Also, should I use StreamReader and StreamWriter (which some tuts use), or should I use NetworkStream, what should I use to transfer the messages?

Community
  • 1
  • 1
Alper
  • 1
  • 12
  • 39
  • 78
  • Could you please explain what WCF is? – Alper Sep 29 '11 at 21:44
  • WCF is "Windows Communication Foundation". It is a framework that covers communications between programs. It can be configured to use various protocols and communications objects, and at the application level you don't have to worry about the details. You can effectively send an object though a socket, without needing to write code to serialize/deserialize the contents. – aaaa bbbb Sep 29 '11 at 21:50
  • More on WCF: Generally in WCF it is easier for the client end to poll the server than it is for the server to send something. The client simply makes a function call, and gets results back from the server. The result can be an object, a list of objects, or anything you can program a function to return. Bottom line: Calls in WCF look like any other function calls, yet the processing can be done on some remote server. – aaaa bbbb Sep 29 '11 at 22:00
  • Or XMPP/Jabber, which is a real chat protocol. Google it. jabber-net is a pretty good client library. – Jonathan Dickinson Sep 29 '11 at 22:25
  • Jabber doesn't look like it has been updated in a few years. WCF might be a bit harder to understand, but it is more general. WCF skills can also help keep you employed. – aaaa bbbb Sep 29 '11 at 22:59

2 Answers2

0

You are on the right track. However you might want to look into some of the more advanced features of WCF, such as Duplex services that will allow a push from the server based on an event.

Matt
  • 3,638
  • 2
  • 26
  • 33
0

Personally, I would just setup a XMPP server and talk it with Jabber.net (http://code.google.com/p/jabber-net/) or something else but I haven't looked in a few years.

kenny
  • 21,522
  • 8
  • 49
  • 87