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.

Edited 4 Years Ago by DavidKroukamp: n/a

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.

Comments
thanks for the help skatamatic
This question has already been answered. Start a new discussion instead.