Revamp network logic. Closes #2
This commit is contained in:
		
							parent
							
								
									6e1d843f79
								
							
						
					
					
						commit
						5c55999771
					
				@ -38,7 +38,6 @@ public class CrabClient implements Crab {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (this.serverAddress == null)
 | 
					            if (this.serverAddress == null)
 | 
				
			||||||
                setup();
 | 
					                setup();
 | 
				
			||||||
            connect();
 | 
					 | 
				
			||||||
            communicate();
 | 
					            communicate();
 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            System.err.println("Error connecting to the server: " + e.getMessage());
 | 
					            System.err.println("Error connecting to the server: " + e.getMessage());
 | 
				
			||||||
@ -97,12 +96,14 @@ public class CrabClient implements Crab {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void sendPacket(byte PID, String argument) throws IOException {
 | 
					    private void sendPacket(byte PID, String argument) throws IOException {
 | 
				
			||||||
 | 
					        connect();
 | 
				
			||||||
        String formattedMessage = String.valueOf((char) PID) + argument + "\n";
 | 
					        String formattedMessage = String.valueOf((char) PID) + argument + "\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        out.print(formattedMessage);
 | 
					        out.print(formattedMessage);
 | 
				
			||||||
        out.flush();
 | 
					        out.flush();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        receiveResponse(PID);
 | 
					        receiveResponse(PID);
 | 
				
			||||||
 | 
					        closeConnection();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void receiveResponse(byte PID) throws IOException {
 | 
					    private void receiveResponse(byte PID) throws IOException {
 | 
				
			||||||
@ -121,8 +122,6 @@ public class CrabClient implements Crab {
 | 
				
			|||||||
            } default -> {
 | 
					            } default -> {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        closeConnection();
 | 
					 | 
				
			||||||
        connect();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void closeConnection() {
 | 
					    private void closeConnection() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user