0% found this document useful (0 votes)
43 views

Networking With Java: Socket Programming

This document discusses Java socket programming and networking concepts. It explains that sockets allow for client-server communication over networks using protocols like TCP and UDP. It provides code examples for basic client and server socket programming in Java to establish connections and exchange data between two processes. Key aspects covered include creating and handling sockets, input/output streams, multi-threaded server design, and looking up IP addresses and URLs.

Uploaded by

Sadhana Kumble
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Networking With Java: Socket Programming

This document discusses Java socket programming and networking concepts. It explains that sockets allow for client-server communication over networks using protocols like TCP and UDP. It provides code examples for basic client and server socket programming in Java to establish connections and exchange data between two processes. Key aspects covered include creating and handling sockets, input/output streams, multi-threaded server design, and looking up IP addresses and URLs.

Uploaded by

Sadhana Kumble
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Networking with Java

Socket programming
The Interweb thing Al Gore
invented…
 Internet is a network of networks.
 The Internet is really people communicating.
 Application layers 7, 6 :
 email, HTTP, FTP, Telnet, file 'sharing', streaming
media, VoIP
 remote access: VPN
 Session layer 5: connections. e.g. sockets
 Transport layer 4: TCP, UDP
 Network layer 3: IP, the Internet
 Link layer 2, 1: NICs, device drivers, magic.
Internet traffic
 10% YouTube HTTP
 36% other HTTP
 37% P2P
 17% newsgroups, streaming, gaming, VoIP

 In other words, mostly a waste of bits.


Internet…what's it good for?
 For years there has been a theory that
millions of monkeys typing at random on
millions of typewriters would reproduce the
entire works of Shakespeare…
The Internet has proven this theory to be
untrue. - Anonymous
Socket Programming
If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your
floppy disk abort,
then the socket packet pocket has an error to
report!
from A Grandchild's Guide to Using Grandpa's
Computer by Gene Ziegler
Sockets programming
 a client exchanging data with a server
 An Internet socket is composed of the
following:
 Protocol (TCP, UDP, raw IP)
 Local IP address (your computer)
 Local port (your application)
 Remote IP address (another computer)
 Remote port (another application)
Server Sockets in Java
 package java.net
 ServerSocket server =
new ServerSocket(PORT);
// waits for network requests.
 Socket socket = server.accept();
// waits for a connection and returns a socket
 use java.io to exchange data
 InputStream from socket (client)
 OutputStream to socket (client)
Client Sockets in Java
 package java.net
 Socket socket = new Socket ( host, port);
// waits for a connection to host on a port and
returns a socket
 use java.io to exchange data
 InputStream from socket (server)
 OutputStream to socket (server)
 see PortScanner.java
URL and IP addresses
 URL class represents a
Uniform Resource Locator, a pointer to a
"resource" on the World Wide Web.
 see ReadURL.java
 InetAddress class represents an
Internet Protocol (IP) address.
 used to find out who the socket is talking to.
 ServerSocket or Socket can .getInetAddress();
Sockets Programming
see
 EchoServer.java & EchoClient.java
 simple two-way communication
 EchoServerThread.java & EchoClient.java
 multi-threaded server to handle many sets of
two-way communication

You might also like