hi all,
I am creating a basic threaded server and chat client... so far everything is going to plan however i am confused as to how i will make two clients(which ever they maybe) connect and send their data to each other.

My idea is in the server app i will make two arrays, one will hold all the seperate client socket connections and the other will hold that clients id, which for now is counter.

so my train of thought goes, each connection the server gets it will save the socket and id of that connection into 2 arrays, each message the server gets it will locate maybe a string "talk" and right after that will be the client id and message i.e "talk1hello", so my server would break up the string and get the id of the client that the other wishes to speak to, i will then search the client id array (on server) for a matching number and once it finds a match i will set the current outgoing socket to the value at which the client id matched that of the client id stored in the server client id array . i am using a flat array which is much like the 2d array however its split into to one dimensional arrays.

so now i can then use my new found data to send the message to the other client, is this a good way or is their maybe a native method in c# for this?

Kind regards.

That would probably the smallest possible packet - though you should delimit each word with a special character that is not typeable (null perhaps). Then split the string based on this character with String.Split().

Another, more OOP friendly way but with much more overhead, would be to look into sending serialized xml data, or serialized classes over sockets with some type of binary formatter. Also, I would use a list of some type rather than an array, since it is much easier to dynamically add and remove items with a list. A list of a simple class or struct containing ID's,IP's and maybe a screen name of a client would do nicely for this purpose.

commented: thanks for the help skatamatic +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.