Networks Sockets and Streams. TCP/IP in action server ports 13 17 80 …65535 lower port numbers (1..1023) are reserved port echo7 time13 ftp20 telnet23.

Slides:



Advertisements
Similar presentations
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Advertisements

Sockets for Clients Socket Basics  Connect to a remote machine  Send data  Receive data  Close a connection  Bind to a port 
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
Referring to Java API Specifications
Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
Programming TCP Clients Version InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Client/Server In Java An Introduction to TCP/IP and Sockets.
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
1 Fall 2005 Socket Programming Qutaibah Malluhi Computer Science and Engineering Qatar University.
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
DBI Representation and Management of Data on the Internet.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
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.
Java Socket programming. Socket programming with TCP.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
Socket-Programming.  Establish contact (connection).  Exchange information (bi-directional).  Terminate contact.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
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.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Socket Programming in Java -First Step of Network Programming-
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Network Programming with Java java.net.InetAddress: public static void main(String[] args) throws UnknownHostException { InetAddress localAddress = InetAddress.getLocalHost();
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Java 13. Networking public class SumTest {
Echo Networking COMP
Network Programming in Java CS 1111 Ryan Layer May 3, 2010
Network Programming Introduction
MCA – 405 Elective –I (A) Java Programming & Technology
Networking with Java 2.
An Introduction to TCP/IP and Sockets
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
CSCD 330 Network Programming
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Networking.
CSCD 330 Network Programming
Distributed Computing
Programming TCP Sockets
Programming TCP Clients
CS18000: Problem Solving and Object-Oriented Programming
Presentation transcript:

Networks Sockets and Streams

TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23 finger79 http80 pop3110

Socket = server + port server = ports …65535 client Socket

The Java Socket Class

Java Socket Class server ports …65535 client Socket instance

Sockets create Streams server ports client Socket instance InputStream OutputStream

class Socket Socket is the Java representation of a TCP network connection Using Socket, a client can create a stream- based communication channel with a remote host To communicate, a socket connection to the remote host must be established - specifying the address and the port There must be a server program actively listening on the port or the connection will fail -- throw an Exception

Socket constructor Socket (String host, int port) throws IOException –port must be by name or text IP address –port must be

java.net.Socket Constructor: Socket (String host, int port) Socket s = new Socket(“ 80); in = s.getInputStream(); int k = in.read(); anInputStream (returns bytes) returns 1st byte of web page s in world of TCP/IP

Socket methods Socket (String host, int port) –constructor InputStream getInputStream () –gets InputStream for reading OutputStream getOutputStream() –get OutputStream for writing

java.net.Socket Constructor: Socket (String host, int port) Socket s = new Socket(“ ”, 80); s in world of TCP/IP out can use IP address written as a string the socket instance acts as a stream “factory” -- design pattern

more Socket methods synchronized void close () –closes the socket void setSoTimeout (int timeout) –Socket will block for only this amt of time - - then InterruptedException is raised

“localhost” “ ”

SocketTest.java import java.io.*; import java.net.*; class SocketTest { public static void main(String[ ] args) { try { Socket t = new Socket(”nova.seas.smu.edu", 13); BufferedReader is = new BufferedReader (new InputStreamReader(t.getInputStream())); (Continued  )

boolean more = true; while (more) { String str = is.readLine(); if (str == null) more = false; else System.out.println(str); } } (Continued  )

catch(IOException e) { System.out.println("Error" + e); } }

Socket t = new Socket(”nova.seas.smu.edu", 13); BufferedReader is = new BufferedReader (new InputStreamReader( t.getInputStream( ) ) );