Networking
Intro to Networking
- Java supports communication over a network
- Allows development of client/server architectures
- Client and server can be written in Java
- Most networking stuff is in java.net
Wrapping Java's Socket Functionality
- It is recommended that a wrapper is used around Java's functionality
- One more layer of abstractions for user
What are Sockets?
- Sockets are the endpoints of a connection in a computer network.
- IP Address: Server's IP Address
- Port Number: Every IP has different ports. Typically numbers between 1024 - 65535
- Out data, In data: Actual communications will take place over a socket, which is available by importing java.net
public class ClientServerSocket
{
private String ipAddr;
private int portNum;
private Socket socket;
private DataOutputStream outData;
private DataINputStream inData;
...
}
ClientServerSocket's Communication Methods
- To start, we'll support communication only of strings
- These methods aren't server or client specific
- This is used to send a string over a scoket's output stream