EE 422C Socket Programming

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
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.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
Java Threads A tool for concurrency. OS schedules processes Ready Running 200 Blocked A process loses the CPU and another.
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.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
System Programming Practical session 10 Java sockets.
System Programming Practical session 11 Multiple clients server Non-Blocking I/O.
A Chat Server DBI – Representation and Management of Data on the Internet.
TCP Socket Programming CPSC 441 Department of Computer Science University of Calgary.
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
19-Aug-15 About the Chat program. 2 Constraints You can't have two programs (or two copies of the same program) listen to the same port on the same machine.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
CSE 219 Computer Science III Network Programming (Application Layer) Reference:
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates.
DBI Representation and Management of Data on the Internet.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 11.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 Rick Mercer Multi Threaded Chat Server. 2 Client – Server with Socket Connections We've seen how to establish a connection with 1 client Review a simple.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
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.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
VII. Sockets. 1. What is a Socket? A socket is one end-point of a two-way communication link between two programs running on the network. Socket classes.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Field Trip #25 Creating a Client/Server By Keith Lynn.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil, Simon Roberts, IBM Corp Advanced Java Programming CSE 7345/5345/ NTU 531 Multithreaded/Sockets/Server Welcome.
Echo Networking COMP
Threads in Java Two ways to start a thread
Network Programming in Java CS 1111 Ryan Layer May 3, 2010
CSE 341, S. Tanimoto Java networking-
Client-server Programming
Socket Programming Cal Poly Pomona Young CS380.
Networking with Java 2.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Socket programming with TCP
CSCD 330 Network Programming
CSI 4118 – UNIVERSITY OF OTTAWA
CSCD 330 Network Programming
CSCD 330 Network Programming
CSCD 330 Network Programming
CSCD 330 Network Programming
CPSC 441 UDP Socket Programming
Distributed Computing
Chapter 2: Application layer
Multiplexing/Demux.
CS18000: Problem Solving and Object-Oriented Programming
Exceptions and networking
Presentation transcript:

EE 422C Socket Programming

Scenario: Chat Program -

Network Connection - Overview

Socket Programming - Concept Socket ( java.net.Socket class) is an object that represents a network connection between two machines. Client wants to make a Socket connection who it is (Server’s IP address), and which service (Server’s port number). 3. Port number is a 16-bit number that identifies a specific program on the server. The port numbers from 0 to 1023 are reserved for well-known services, pick your port number from 1024 to 65535.

Socket Programming - Connect

Socket Programming - Connect (cont.) ServerSocket serverSock = new ServerSocket(4242); while(true) { Socket clientSocket = serverSock.accept(); Thread t = new Thread(new ClientHandler(clientSocket)); t.start(); System.out.println("got a connection"); } Server Socket clientSock = new Socket(“190.165.1.103”,4242); Client

Socket Programming - Send

Socket Programming - Send

Socket Programming - Receive

Socket Programming - Receive

Socket Programming - iClicker (2) How does a client know the host’s IP address when requesting a socket connection? By querying the host directly By looking up the host’s IP address in some database, like a DNS, or some means outside the program. Other

Socket Programming - Example Example: Chat Server and Chat Client

Example - Client public class ChatClient { private BufferedReader reader; private PrintWriter writer; private JTextArea incoming; private JTextField outgoing; ... private void setUpNetworking() throws Exception { Socket sock = new Socket("127.0.0.1", 5000); InputStreamReader streamReader = new InputStreamReader(sock.getInputStream()); reader = new BufferedReader(streamReader); writer = new PrintWriter(sock.getOutputStream()); Thread readerThread = new Thread(new IncomingReader()); readerThread.start(); } class IncomingReader implements Runnable { public void run() { String message; while ((message = reader.readLine()) != null) { incoming.append(message + "\n"); }}

Example - Server public class ChatServer { private ArrayList<PrintWriter> clientOutputStreams; private void setUpNetworking() throws Exception { clientOutputStreams = new ArrayList<PrintWriter>(); ServerSocket serverSock = new ServerSocket(5000); while (true) { Socket clientSocket = serverSock.accept(); PrintWriter writer = new PrintWriter(clientSocket.getOutputStream()); Thread t = new Thread(new ClientHandler(clientSocket)); t.start(); clientOutputStreams.add(writer); System.out.println("got a connection"); }

Example - Server (Cont.) class ClientHandler implements Runnable { private BufferedReader reader; public ClientHandler(Socket clientSocket) throws IOException { Socket sock = clientSocket; reader = new BufferedReader(new InputStreamReader(sock.getInputStream())); } public void run() { String message; while ((message = reader.readLine()) != null) { notifyClients(message); private void notifyClients(String message) { for (PrintWriter writer : clientOutputStreams) { writer.println(message); writer.flush(); } 17

Example - Client (Cont.) public class ChatClient { ... private void initView() { outgoing = new JTextField(20); JButton sendButton = new JButton("Send"); sendButton.addActionListener(new SendButtonListener()); class SendButtonListener implements ActionListener { public void actionPerformed(ActionEvent ev) { writer.println(outgoing.getText()); writer.flush(); }

Example - Chat Program Demo: Chat Server and Chat Client

Recall: Observer Design Pattern

Observer Design Pattern

Example - Chat Program Demo: Chat Program with Observer Design Pattern

Socket Programming - Summary