1 / 8

Introduction to Computing Concepts

Introduction to Computing Concepts. Note Set 23. Networking. IP: 192.168.0.123. Network. IP: 97.99.88.77. IP: 111.222.121.99. ClientServer Model. Data Transfer Between client and server. Client- Actively makes a Connection to the server. Server- Waits Passively

cathal
Download Presentation

Introduction to Computing Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computing Concepts Note Set 23

  2. Networking IP: 192.168.0.123 Network IP: 97.99.88.77 IP: 111.222.121.99

  3. ClientServer Model Data Transfer Between client and server Client- Actively makes a Connection to the server Server- Waits Passively for a connection Each computer has many “ports” that allow it to communicate with More than one other computer.

  4. In Java - Server Let’s say this server is running on computer w/ IP 192.168.0.101 ServerSocket listener = new ServerSocket(3333); Socket connection; //Blocks and waits for someone to attempt to connect //Will accept the connection only on the port listed above connection = listener.accept(); //More code to come So a client on another computer would attempt to connect to IP 192.168.0.101 on port 3333.

  5. In Java - Client Let’s say this client is running on computer w/ IP 192.168.0.202 //attempt to connect to server running on Socket client = new Socket(“192.168.0.101”, 3333);

  6. Communication • Two computer connected to the same socket can send and receive information to/from each other //attempt to connect to server running on Socket client = new Socket(“192.168.0.101”, 3333); //Write to socket with a printwriter PrintWriter output = new PrintWriter(client.getOutputStream()); //Read from socket with a Scanner – just like from //the keyboard Scanner input = new Scanner (client.getInputStream());

  7. Exception Handling • Helps recover from runtime errors • Try to connect to a server but can’t get a connection • Some methods throw exceptions that must be caught in the code you write. try { //attempt to connect to server running on Socket client = new Socket(“192.168.0.101”, 3333); } catch (Exception e) { System.out.println(“Error”); System.out.println(e.getMessage()); }

  8. Breakout IN Groups • Modify Simple Server • Have server generate a random number between 1 and 10, then wait for a connection • Upon connection, read a number from the input stream and check. • Send back to client a message of correct guess or incorrect guess • Modify Simple Client • Get a number between 1 and 10 from the user • Connect to server and then send number • Read back response and display to the user

More Related