1 / 6

CSE 1341 - Honors Principles of Computer Science I

CSE 1341 - Honors Principles of Computer Science I. Mark Fontenot mfonten@engr.smu.edu. Note Set 11. Note Set 11 Overview. Networking IP address and Ports Client/Server Ideas Java Networking Server Socket Socket. IP and Ports. Server. IP: 92.113.223.90 Servers run on ports.

lois
Télécharger la présentation

CSE 1341 - Honors Principles of Computer Science I

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. CSE 1341 - HonorsPrinciples of Computer Science I Mark Fontenot mfonten@engr.smu.edu Note Set 11

  2. Note Set 11 Overview • Networking • IP address and Ports • Client/Server Ideas • Java Networking • Server Socket • Socket

  3. IP and Ports Server IP: 92.113.223.90 Servers run on ports IP: 129.119.101.111 Internet Ports: Each computer has port #s between 0 and 65,535. OS usually reserves 1024 for system services (80 for WWW, 21 for FTP)

  4. Server/Client Server: Handles requests from clients serv = create new ServerSocket to listen on some port while (true) { if (serv.iHaveAConnection()) Handle client connection } Client: Connects to Server client = create new socket to IP addr and port while (i have more stuff to do with server){ Send data to server Read data from server } close client

  5. ServerSocketserver; Socket client; try { server = new ServerSocket(8856); client = server.accept(); System.out.println("Got a live one. IP:" + client.getInetAddress().getHostName()); Scanner netReader = new Scanner(client.getInputStream()); System.out.println(netReader.nextLine()); netReader.close(); client.close(); server.close(); } catch (Exception e) { System.out.println(e.getMessage()); } Server Code

  6. Client Code try { //Connect to server Socket client = new Socket ("localhost", 8856); //Create a PrintWriter object that will allow us to //write to the server PrintWriter pw = new PrintWriter(client.getOutputStream()); //send a message to the server using pw pw.println("Hello Server"); pw.close(); client.close(); } catch (Exception e) { System.out.println(e.getMessage()); }

More Related