fredericmarchand / RealTimeVotingSystem

Real-Time Concurrent Systems
0 stars 1 forks source link

Fix for concurrency issues with socket #19

Closed brandonSc closed 9 years ago

brandonSc commented 9 years ago

It is probably too last minute to try to implement this, but I have an idea that could resolve the concurrency issues we are having with socket class.

I think we should make a WServerSocket class that listens on a single port and has an accept() method that returns a new WSocket instance. The server logic would then look like:

  1. When the server starts, init the server socket socket = new WServerSocket(60002)
  2. in a loop, call socket.accept() which returns a new WSocket on an entirely new port, which is only connected to that single client. accept() would essentially make a new socket on any available port, and then send the new port to the client. The client would then start sending it's messages to the new port instead of the port it used to initially connect to the server with.
  3. Have the server start a new thread for that socket to handle only that specific client's requests. This way, each client is handled separately in a new thread on their own socket.

This way we are never trying to send messages to different clients on the same port. Plus this is the way java's TCP socket classes work. I'll work on adding this soon, but I think it's too risky to try and do before submitting tonight.