These are some of the original ideas for the project structure:
1. The first idea was to connect both of the clients with the server using TCP sockets.
The communication was going to be handled by the Server in the following way:
The user will send a message to the server
The server will take the message and send it to every body that is connected
This implies that a direct connection between users was going to be none existent.
2. The second idea was similar to the first idea, the only difference is that instead of TCP Sockets I was going to use UDP sockets.
3. The third idea is a mixture of the previews two. I decided to create a TCP connection to the server. This way we do not relay on the server as much and the work can be more evenly distributed. The purpose of the TCP connection with the server is to keep the server constantly updated of the connectivity of all the users. The communication between clients will be made by using UDP sockets, to send and receive data.
The client will request the server an updated list of IP addresses of the users connected. The server will return a String with all the IP addresses. Once this string has been received, the client will parse the string and start sending message to all the different users.
I decided to stay with the third one, because this way I can make the work between the three different parts of the project more evenly distributed. At the same time the operation between them will not be too compromised since the dependence between them is not as high.
The final product will look as fallows:
The first part of the project is a server, which is able to accept as many as 200 different client connections. These connections can be made by computers using a C# interface or any Android Device using a application in Java.
The connection will be made using TCP Sockets.
The server will accept the connection, create an object called client, this object will have all the methods necessary for the communication between server and user. Once the object has been created the server binds the stream to it and puts it on a Linked lists, and continues listening for other users.
The reason I put the clients in a linked list is so the server does not need to worry about the interaction with the client any more, and it can still listen for other clients to connect.
When a client connects to the server, the client surrenders its own IP address.
When a clients requests other clients IP addresses it also sends its current IP address in case this has change since the last time.
The IP address will be put on a String Array that will be available for all the users.
The communication between users is achieved using UDP sockets. Since these sockets do not need a connection in order to communicate it makes it easier to broadcast from one device to all the other connected.
All the users will be able to communicate with each other at the same time. The idea is to create a many to many connections. One individual is able to send messages or send data to all other devices connected to the server. At the same time this one device will be able to receive all messages and data from all other devices connected at the moment.
The only problem using UDP Sockets is that is that the user is not guaranteed that it will receive the message, since this message or data might get lost in the way. Even with this issue, it represents the best answer for a fast communication between many points to many points.
The connection between users looks as follows:
If we tried to implement this idea using TCP sockets, each client will have to have a connection with all other clients. This will represent time, and complexity to the program. The pro for this is that the user is guaranteed that it will get the message.
I decided to go for speed and simplicity on the user communication since the loosing a message is not a so likely to happen.
The weight of loosing one message does not represent a big deal when sending some of the data as long as you get the majority of them.
Users prefer speed than quality.
I decided to give up speed and simplicity on the server-client communication because users need to have a guaranty of getting all the IP addresses of the people connected.
Code:
Server ServerClientObject ClientForm1 ClientCallObject JavaClient