Networking in Java Socket Proxy Server Internet Address

  • Slides: 23
Download presentation
Networking in Java • • • Socket , Proxy Server , Internet. Address Inet.

Networking in Java • • • Socket , Proxy Server , Internet. Address Inet. Address Class URL connection class TCP/IP Communication

Socket • Communication Point • Electrical Socket • Use by TCP and UDP

Socket • Communication Point • Electrical Socket • Use by TCP and UDP

Reserve Socket Protocol Port Purpose Echo 7 Test machine connect or not Daytime 13

Reserve Socket Protocol Port Purpose Echo 7 Test machine connect or not Daytime 13 Gives Currant time on server ftp 20 Transfer File smtp 25 Use for mails http 80 Get webpage finger 79 Info of user on local system nntp 119 Network news transfer protocol

Proxy Server • • Client restriction to connect server Client-proxy server-server Caching and request

Proxy Server • • Client restriction to connect server Client-proxy server-server Caching and request filtering Reduce bandwidth allocation

Internet Address • IPv 4 • IPv 6 • resolver

Internet Address • IPv 4 • IPv 6 • resolver

Classes in java. net • • • Socket Datagram. Packet Inet. Address URLConnection

Classes in java. net • • • Socket Datagram. Packet Inet. Address URLConnection

Interfaces in java. net • File. Name. Map • Socket. Options • Socket. Impl.

Interfaces in java. net • File. Name. Map • Socket. Options • Socket. Impl. Factory • URLStream. Handler. Factory

Exception in java. net • Socket. Exception • Protocol. Exception • Connect. Exception •

Exception in java. net • Socket. Exception • Protocol. Exception • Connect. Exception • Unknown. Host. Exception

Inet. Address • Encapsulate IP address and domain name • Factory Method: get. Local.

Inet. Address • Encapsulate IP address and domain name • Factory Method: get. Local. Host() get. By. Name() get. All. By. Name() Throws Unknown. Host. Exception

Instance Methods • • • boolean equals byte get. Address String get. Host. Name

Instance Methods • • • boolean equals byte get. Address String get. Host. Name String get. Host. Address boolean is. Multicast. Address

TCP/IP Client Socket • • Reliable, Bidirectional and Point-Point TCP socket for Client and

TCP/IP Client Socket • • Reliable, Bidirectional and Point-Point TCP socket for Client and Server. Socket Use of Socket to Connect Client -Server

Client Socket • • Socket (Host. Name, Port Number) Socket (Inet. Address ipaddress, Port

Client Socket • • Socket (Host. Name, Port Number) Socket (Inet. Address ipaddress, Port Number) get. Inet. Address() get. Port() get. Local. Port() get. Input. Stream()-Input. Stream get. Output. Stream()-Output. Stream

Server. Socket • Server. Socket(int port) Max 50 Client • Server. Socket(int port, int

Server. Socket • Server. Socket(int port) Max 50 Client • Server. Socket(int port, int Maxclient) • Server. Socket(int port, int mc, inetaddress ipaddress) Bind Exception Accept() Close()

Life Cycle of Server. Socket • • • Creation of serversocket Listen for incomming

Life Cycle of Server. Socket • • • Creation of serversocket Listen for incomming connection Communicate with client Interaction in client and server Any one or both close connection Server wait for next connection

TCP vs UDP TCP UDP Connection Oriented Connection Less Reliable Non Reliable Not Support

TCP vs UDP TCP UDP Connection Oriented Connection Less Reliable Non Reliable Not Support Broadcasting Provide Error and Flow Not Provide Flow and Control Error Control TCP Packet called UDP Packet called segment Datagram

URL Class • URL (String URL) • URL (String protocol, String Host, int port,

URL Class • URL (String URL) • URL (String protocol, String Host, int port, String File path) • URL (String protocol, String Host, String File path) • Malformed. URLException

URL Methods • get. Protocol() • get. Host() • get. Port() • get. File()

URL Methods • get. Protocol() • get. Host() • get. Port() • get. File() • to. External. Form()

URLConnection • It use to find out header information of URL with connection. •

URLConnection • It use to find out header information of URL with connection. • Steps: • Construct URL Object • Invoke open. Connection method • Configure URL connection • Read header files • Get inputstream and outputstream to read or write data • Close Connection.

URL VS URLConnection • URLConnection provide access to http header • Configure request parameter

URL VS URLConnection • URLConnection provide access to http header • Configure request parameter sent to server. • It can read or write data from server

Methods • get. Content. Type() • get. Content. Length() • get. Date() • get.

Methods • get. Content. Type() • get. Content. Length() • get. Date() • get. Expiration() • get. Last. Modified()

java. security • Contains classes and interface for security architecture. • Access Control: Prevent

java. security • Contains classes and interface for security architecture. • Access Control: Prevent untrusted code to perform sensitive operation • Authentication Class: Message digest + Digital Signature • Access Control mainly contains Permission and Policy class

Permission class • Files or network connection • Permission name and set of actions

Permission class • Files or network connection • Permission name and set of actions • get. Name() and get. Actions() • Implies method has set of permissions

Policy class • Whetever given class has permission to access given system resource •

Policy class • Whetever given class has permission to access given system resource • What permission granted to what code • get. Policy() and set. Policy() • At time only one policy in effect