Home
>>     < >




In-class notes for 01/10/2018

CS 284 (MCA), Interim 2018

This session: Lab 6: Networking communication in Java

Submitted questions on assignments and technology

Network communications in Java

  • Network concepts: host name, TCP ports. (Port assignments per person)

  • Basics of network communication via sockets:

    • Socket as an endpoint for communication. Need to connect sockets on different hosts.

    • The Socket and ServerSocket classes

      • Socket connect() method for attempting to connect via a "server socket" on a particular host and port.

      • ServerSocket accept() method for receiving connection requests. If an accept() call succeeds, it returns a fresh Socket object for the server to communicate to that client that requested connection.

    • Can then obtain OutputStream(s) and/or InputStream(s) from Socket objects to perform I/O operations across the network.

    • Close sockets when finished.

  • Exercise: Find these elements in net/Sender.java and net/Receiver.java

  • Demo of net/Sender.java and net/Receiver.java

  • Exercise: Compile and run these programs in class together with someone else on another Link machine.

Lab exercises and javadoc

  • Objects representing individual network communications (Message classes).

  • Defining constructors in Java (see constructor in Account.java)

  • The javadoc documentation system; stub implementations (example: Account.java members other than constructor)

    • Annotations: /**, @param, @return, @exception, @author

    • % javadoc -author -package Account.java

    • Results: Account.html

  • The class StringTokenizer for parsing strings. Methods nextToken() and countTokens().

Looking ahead

React native GUIs - Deandre




< >