TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.

Slides:



Advertisements
Similar presentations
Categories of I/O Devices
Advertisements

Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public ITE PC v4.0 Chapter 1 1 OSI Transport Layer Network Fundamentals – Chapter 4.
HTTP Cookies. CPSC Application Layer 2 User-server state: cookies Many major Web sites use cookies Four components: 1) cookie header line of HTTP.
COEN 445 Communication Networks and Protocols Lab 4
Network Programming Chapter 11 Lecture 6. Networks.
Socket Programming.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
1 © 2003, Cisco Systems, Inc. All rights reserved. CCNA 1 v3.0 Module 11 TCP/IP Transport and Application Layers.
File Transfer: FTP and TFTP
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Client Server and Protocols. Servers and Clients 4 A “server” is just a computer running a piece of software that provides resources to clients 4 A client.
User Datagram Protocol UDP. Remember, UDP is Not reliable; data may be dropped No guarantee of in-order delivery Duplicate data is possible No built-in.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
What Is TCP/IP? The large collection of networking protocols and services called TCP/IP denotes far more than the combination of the two key protocols.
Internet Basics.
Introduction 1 Lecture 7 Application Layer (FTP, ) slides are modified from J. Kurose & K. Ross University of Nevada – Reno Computer Science & Engineering.
File Transfer Protocol (FTP)
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Process-to-Process Delivery:
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
4-Oct-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you send.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
1 7-Oct-15 OSI transport layer CCNA Exploration Semester 1 Chapter 4.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Transport Layer COM211 Communications and Networks CDA College Theodoros Christophides
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
4343 X2 – Outline The Domain Name System The Web.
Transmission Control Protocol (TCP) Internet Protocol (IP)
1 Tips for the assignment. 2 Socket: a door between application process and end- end-transport protocol (UDP or TCP) TCP service: reliable transfer of.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
COMPUTER NETWORKS Hwajung Lee. Image Source:
1 Network Communications A Brief Introduction. 2 Network Communications.
Process-to-Process Delivery:
Networking Mehdi Einali Advanced Programming in Java 1.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Sockets and Beginning Network Programming
Networking COMP
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Lecture 6: TCP/IP Networking By: Adal Alashban
Topic 5: Communication and the Internet
Chapter 14 User Datagram Protocol (UDP)
Process-to-Process Delivery:
Lecture 6: TCP/IP Networking 1nd semester By: Adal ALashban.
Starting TCP Connection – A High Level View
Chapter 7 Network Applications
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
TCP/IP Sockets in Java: Practical Guide for Programmers
Exceptions and networking
Presentation transcript:

TCP Sockets Reliable Communication

TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery No duplicates Rate-limiting It allows you to write to another host on the network as if it were a file stream TCP only passes bytes; it is completely agnostic about what they mean. Making sense of the bytes is up to you, the programmer (or the protocol receiving the bytes)

Review To connect to a host, we need to specify: What host we will be talking to, either directly via IP number, or indirectly via DNS name What port on the host we will be talking to; a number in the range 0-64K

Socket A “socket” describes a connection between two hosts To set up a stream between two hosts you need a “socket pair” that describes the connection between the client and the server Server Client Port TCP 4567Port TCP 4485

Socket The socket pair can be described as (( , 4567), ( , 4485)) The client IP, a client port, the server IP, and the well- known port we connect to on the server If you’re picky, you also need to specify whether this is TCP or UDP. This is often omitted, though, because it’s usually clear from the context which is being used

Server Socket The standard technique is: client initiates connection to server Before we can establish a connection, we have to have something waiting for the connection on the server side This is a “server socket”, a piece of software that waits for clients to connect.

Server Socket Waiting for a connection at , 4485 Server Client Port TCP 4567Port TCP 4485

Multiple Connections What if two people want to connect to a web server at the same time? Notice that the socket connection has a unique ID based on the socket pair. If two hosts connect, or even if two programs from the same host connect You can see this with “netstat -an”

Netstat hodad-5:MV3500 mcgredo$ netstat -an Active Internet connections (including servers) Proto Recv-Q Send-Q Local Address Foreign Address (state) tcp ESTABLISHED tcp ESTABLISHED tcp ESTABLISHED

Two Connections from Same Host Server Client Port TCP 4567Port TCP 4485 Port TCP 4568Port TCP 4485 What are the socket pairs here?

Connection Process (Java) The server starts a server socket on a port; this will listen on, for example on port 1234 The client initiates a connection from its IP to the server. The client picks an unused port on the client machine, and this port is used in the socket pair. The client port is sometimes called an “ephemeral port” At this point we have a socket pair. The client code returns a socket object, and the server code returns a similar socket object Note that a Socket object is not a ServerSocket object!

Socket InputStream OutputStream The inputStream on one side of the Socket is connected to the outputStream On the other side, and vice versa

Input & Output Streams Input & Output streams are standard Java objects that know how to read & write bytes only. They don’t know about higher level concepts like Unicode characters, integers, floating point numbers, etc But: are you convinced that with enough work you could write a class that figured out what four bytes represented as a floating point number? Luckily for you, there are classes in the standard Java library that do this for you

Input & Output Streams PrintStreamOutputStream Unicode rep of data InputStream Reader Buffered Reader

Other Streams There are also Java library streams for reading & writing binary values, and streams for reading and writing Java objects (!) Remember, bytes are bytes; sockets are agnostic about what they mean. We have to come to some sort of a priori agreement on what we’ll be sending so we’ll know what to expect on the receiving side The string value “17.4” is not the same as a binary floating point number representing 17.4

Sliding Window TCP works via something called a“sliding window”. Simplified, it looks something like this: Sent, Ack’d Sent, No ack yet Ready To Send Sliding Window

The rate at which it sends depends on how quickly it gets acks back. If the window is a fixed size, it can’t move right until the leftmost data is ack’d This means you may not be able to send new data until old data is acked! For something like position updates this is bad But this can be used to do rate limiting, congestion control, etc.

Example Code See TcpServer.java, TcpClient.java This simply establishes a connection and sends a simple message and response

Message Format? So what type message should you send? Since you get to make it up, it’s good for you if you pick something simple and robust For TCP sockets, this is usually ASCII text Why? Binary is different from host to host You can easily debug ASCII it is usually fast enough for what TCP does You can use binary formats, but your default first attempt should be ASCII

Examples of TCP Message Formats You can establish your own interactive TCP connection to a server with “telnet ” (usually typing blind on windows machines) HTTP (web servers): GET /index.html SMTP ( ) fake mail

HTTP telnet 80www.movesinstitute.org GET /index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " <!-- InstanceBegin template="/Templates/level_1.dwt" codeOutsideHTMLIsLocked="false" -->

SMTP Fak telnet mustang.nps.edu 25 MAIL FROM: RCPT TO: DATA You are instructed to appear at the next inspection in a speedo. QUIT Note the period on a line by itself

Stateless vs. Stateful Protocols Note a subtle difference between the HTTP and SMTP protocols HTTP is stateless--you send one text command, the server processes that, and then the socket connection can be torn down and the server completely forgets that it ever talked to you before A stateful protocol depends on prior commands sent from the client. The RCPT TO and DATA commands depend on the prior MAIL FROM command. Stateless protocols are good. They scale well, and are simple.

Sequential vs Parallel What happens to our simple ping-pong example if the server takes a long time to process a command? How can we fix this? Use a thread per client connection--then we can go back and do another accept() wile the first command is still processing This is a parallel server

TCP Protocols You want to use text for the protocol commands if you possibly can Keep it simple. Simple can be debugged and may actually work. Complex will not. If you possibly can, start off with a sequential, stateless server

Matrix Stateless Stateful Sequential Parallel X Try for a stateless, sequential protocol if you can, on the grounds that it’s simple. Going to a parallel implementation is not bad, but a stateful protocol can be much more complex

Assignment Write a client and server that accepts a simple position command for an entity. Include an entity identifier and position (x,y,z) Write a simple HTTP client program that sends a request for a URL to a server and gets a response back