Tcp/Ip
Tcp/Ip
Topics
IPv6 availability
An option with Windows 2000/NT Most routers can support IPV6 Supported in J2SDK/JRE 1.4
Netprog 2002 TCP/IP
Overcome IPv4 scaling problem Flexible transition mechanism. New routing capabilities. Quality of service. Security. Ability to add features in the future.
Netprog 2002 TCP/IP
IPv6 Headers
No optional fields - fixed size (40 bytes) No fragmentation fields. No checksum more flexible than simple protocol field.
4 for IPv4
IPv4 Header
1 byte VERS 1 byte 1 byte 1 byte HL Service Fragment Length Datagram ID FLAG Fragment Offset TTL Protocol Header Checksum Source Address Destination Address Options (if any) Data
6 for IPv6
IPv6 Header
1 byte 1 byte 1 byte Flow Label Next Header 1 byte Hop Limit
VERS: 6 (IP version number) Priority: will be used in congestion control Flow Label: experimental - sender can label a
sequence of packets as being in the same flow. Payload Length: number of bytes in everything following the 40 byte header (up to 64Kb), or 0 for a Jumbogram (up to 4Gb).
Netprog 2002 TCP/IP
protocol field - indicates what type of header follows the IPv6 header.
Extension Headers
IPv6 Addresses
TLA: top-level aggregation (provider) NLA: next-level (subscriber) SLA: site-level (subnet) Interface ID is (typically) based on hardware MAC address Netprog 2002 TCP/IP
address of a host, but the host only has an IPv4 address. DNS creates the IPv4-Mapped IPv6 address automatically. Kernel understands this is a special address and really uses IPv4 communication.
Netprog 2002 TCP/IP
host supporting IPv6 to talk IPv6 even if the local router(s) dont talk IPv6. IPv4 compatible addresses tell endpoint software to create a tunnel by encapsulating the IPv6 packet in an IPv4 packet.
Netprog 2002 TCP/IP
Tunneling (done automatically by kernel when IPv4-Compatible IPv6 addresses used) IPv6 Host
IPv4 Routers IPv4 Datagram IPv6 Datagram
IPv6 Host
http://java.sun.com/j2se/1.4/docs/guide/net/ipv6_guide/
Connection-Oriented
a virtual connection is established before any user data is transferred. If the connection cannot be established - the user program is notified. If the connection is ever interrupted - the user program(s) is notified.
Netprog 2002 TCP/IP
Reliable
transmission of data is acknowledged by the receiver. If the sender does not receive acknowledgement within a specified amount of time, the sender retransmits the data.
Netprog 2002 TCP/IP
Byte Stream
Buffering
TCP to send the data it has buffered without waiting for a buffer to fill up.
Full Duplex
TCP Ports
TCP Segments
data bytes from the byte stream control information that identifies the
Netprog 2002 TCP/IP
TCP Lingo
sends a SYN segment (a special TCP segment) to the server port. SYN stands for synchronize. The SYN message includes the clients ISN. ISN is Initial Sequence Number.
More...
Sequence Number that refers to the first byte of data included in the segment. Every TCP segment includes an Acknowledgement Number that indicates the byte number of the next data that is expected to be received.
And more...
URG: urgent data included. ACK: this segment is (among other things)
an acknowledgement. RST: error connection must be reset. SYN: synchronize Sequence Numbers (setup) FIN: polite connection termination.
Netprog 2002 TCP/IP
And more...
option) Window: Every ACK includes a Window field that tells the sender how many bytes it can send before the receiver will have to toss it away (due to fixed buffer size).
Client Starts
Clients ISN (generated pseudo-randomly) Maximum Receive Window for client. Optionally (but usually) MSS (largest
datagram accepted). No payload! (Only TCP headers)
Server Response
Servers ISN (generated pseudo-randomly) Request Number is Client ISN+1 Maximum Receive Window for server. Optionally (but usually) MSS No payload! (Only TCP headers)
Netprog 2002 TCP/IP
Finally
Client
SYN SYN ISN=X ISN=X 1
Server
ACK=Y+1 3 ACK=Y+1
Client: I want to talk, and Im starting with byte number X. Server: OK, Im here and Ill talk. My first byte will be called number Y, and I know your first byte will be number X+1. Client: Got it - you start at byte number Y+1. Bill: Monica, Im afraid Ill syn and byte your ack Netprog 2002 TCP/IP
3 ?
Why 3-Way?
data can be sent. Each data segment includes a sequence number identifying the first byte in the segment. Each segment (data or empty) includes a request number indicating what data has been received.
Netprog 2002 TCP/IP
Buffering
Operating System. The O.S. takes care of all these details asynchronously. The TCP layer doesnt know when the application will ask for any received data. TCP buffers incoming data so its ready when we ask for it.
Netprog 2002 TCP/IP
TCP Buffers
with every ACK how much buffer space remains (the Window field in a TCP segment).
Send Buffers
some data to send. The data is put in a send buffer, where it stays until the data is ACKd. The TCP layer wont accept data from the application unless (or until) there is buffer space.
Netprog 2002 TCP/IP
ACKs
out-of-order segments (if there is room in the buffer). Once the missing segments arrive, a single ACK can be sent for the whole thing. Remember: IP delivers TCP segments, and IP is not reliable - IP datagrams can be lost or arrive out of order.
Netprog 2002 TCP/IP
Termination
segment that terminates a connection if something is wrong. Usually the application tells TCP to terminate the connection politely with a FIN segment.
FIN
App1
FIN FIN SN=X SN=X ACK=X+1 ACK=X+1 1
App2
...
FIN FIN SN=Y SN=Y 3 ACK=Y+1 4 ACK=Y+1
Netprog 2002 TCP/IP
TCP Termination
1 2
App1: I have no more data for you. App2: OK, I understand you are done sending. dramatic pause App2: OK - Now Im also done sending data. App1: Roger, Over and Out, Goodbye, Hastalavista Baby, Adios, Its been real ... camera fades to black ...
Netprog 2002 TCP/IP
3 4
TCP TIME_WAIT
Address already determined. Tell the kernel to accept incoming connection requests directed at the socket address.
3-way handshake
the close() system call. If the other end has closed the connection, and there is no buffered data, reading from a TCP socket returns 0 to indicate EOF.
Client Code
3-way handshake
Netprog 2002 TCP/IP
d() To succeed in relationships: bin you need to establish your own identity. accept() you need to be open & accepting.
you need to establish contacts. connect() you need to take things as they come, not you need to handle problems as they arise. rs
check for erro
Netprog 2002 TCP/IP
for sockets programming Typically you import everything defined in this package with:
import java.net.*;
Netprog 2002 TCP/IP
Classes
InetAddress Socket ServerSocket DatagramSocket DatagramPacket
UDP UDP
Socket class
Socket Constructors
Socket Methods
void close(); InetAddress getInetAddress(); getpeername InetAddress getLocalAddress(); getsockname InputStream getInputStream(); OutputStream getOutputStream();
Socket I/O
Constructors:
ServerSocket(int port); ServerSocket(int port, int backlog); ServerSocket(int port, int backlog, InetAddress bindAddr);
Netprog 2002 TCP/IP
ServerSocket Methods
Socket accept(); void close(); InetAddress getInetAddress(); int getLocalPort();
throw IOException, SecurityException
Netprog 2002 TCP/IP