0

im trying to create a multi-threading connection by creating a new thread that will allow the client to send and receive messages. the issue im facing is all the errors that are displayed within my code and im unsure where to start and how to establish this code to conduct an actual connection. Thank you anyone that does come across and help.

package sendmessage;

Thread SendMessage = new Thread(new Runnable() {

        @Override

        public void run() { 

            while (true) { 



                // read the message to deliver. 

                String msg = sc.nextLine(); 

                try { 



                    // write on the output stream 

                    dos.writeUTF(msg); 

                } catch (IOException e) { 

                    e.printStackTrace(); 

                } 

            } 

        } 

    }); 

package readmessage;

Thread ReadMessage = new Thread(new Runnable() {

        @Override

        public void run() { 



            while (true) { 

                try { 



                    // read the message sent to this client 

                    String msg = dis.readUTF(); 

                    System.out.println(msg); 

                } catch (IOException e) { 



                    e.printStackTrace(); 

                } 

            } 

        } 

    }); 
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
Cryces
  • 37
  • 1
  • 1
    What are the errors, and can you edit the question to put the errors and their stack traces into the question? – NomadMaker Apr 19 '20 at 02:54
  • It would also be good to reformat you Question so that all code statements are in the "code" blocks, and so that there isn't a blank line between each statement. Your code is hard to read. – Stephen C Apr 19 '20 at 02:57
  • the error is – Cryces Apr 19 '20 at 03:28
  • 1) Those are not complete classes. There is no `class` declaration for a start. 2) Your client and server code classes (presumably) need `main` entry point methods so that they can be run. See the linked Q&A. – Stephen C Apr 19 '20 at 05:53

0 Answers0