Java Sockets Brad Vander Zanden. Agenda What are sockets Client/Server interaction Single client/server example Synchronized data objects Multi-threaded.

Slides:



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

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.
Real-Time Authentication Using Digital Signature Schema Marissa Hollingsworth BOISECRYPT ‘09.
1 L54 Networking (3). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Distributed systems Programming with threads. Reviews on OS concepts Each process occupies a single address space.
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.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L23 (Chapter 25) Networking.
Java sockets. From waiting.
Multithreaded Java COMP1681 / SE15 Introduction to Programming Fast Track Session 3.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Chat Room Project (IM- E2003) Supervised by : Dan Witzner Hansen Group Member: Xijie Lu Vu Pham To IT University of Copenhagen 23rd Jan.2004.
Aalborg Media Lab 15-Jul-15 Java & EyesWeb Lecture 14 Java Client / Server Communication.
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
Networks and Client/Server Applications. Basics of Client/Server One host computer can have several servers Several clients can connect to a server Client.
Fundamentals of Python: From First Programs Through Data Structures
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.
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 References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
Hands On Networking Socket Programming Ram P Rustagi, ISE Dept Abhishek Gupta, ISE Dept Laxmi Kuber, MCA Dept June 28-30, 2012.
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
University of Pittsburgh Computer Science 1 Week 5: Introduction Last week we discussedLast week we discussed èDifference between executing sequentially.
Introduction to Interprocess communication SE-2811 Dr. Mark L. Hornick 1.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
The TELNET Protocol Mozafar Bag Mohammadi.
CS4273: Distributed System Technologies and Programming Lecture 13: Review.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 11.
Establishing communication with Envirobat using TCP/IP Presented by Apourva Parthasarathy Date : 18/06/13.
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
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.
Process Synchronization I Nov 27, 2007 CPE Operating Systems
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 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
Sockets Sockets A socket is an object that encapsulates a TCP/IP connection There is a socket on both ends of a connection, the client side and the server.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Networking and Concurrency COMP.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Practical Session 12 Reactor Pattern. Disadvantages of Thread per Client It's wasteful – Creating a new Thread is relatively expensive. – Each thread.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
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.
CSC 480 Software Engineering Socket. What is Socket? A socket is one end-point of a two-way communication link between two programs running on the network.
Field Trip #25 Creating a Client/Server By Keith Lynn.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology SDL_net Client-Server Example Spring 2012.
©The McGraw-Hill Companies, Inc., 2000© Adapted for use at JMU by Mohamed Aboutabl, 2003Mohamed Aboutabl1 1 Chapter 15 Application Layer and Client-Server.
Socket Programming.
Chapter 17 - Clients + Servers = Distributed Computing Introduction Large Computers Use Networks For Input and Output Small Computers Use Networks To Interact.
Netprog: TELNET1 The TELNET Protocol Reference: RFC 854.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
Netprog: TELNET1 The TELNET Protocol Mozafar Bag mohammadi.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
CSC 480 Software Engineering Lab 2 – Multi-Threading Oct 18, 2002.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Process Synchronization I CPE Operating Systems
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
Multi player client sever Snake Game Technology : JAVA (swing for user interface and Socket for passing coordinates of snakes, food item and score)
Sockets A popular API for client-server interaction.
Network Programming. These days almost all devices.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
The Echo Server Problem. Contents  Basic Networking Concepts  The Echo Server Problem.
Introduction to threads
Threads in Java Two ways to start a thread
Block 15 Developing the Calculator application
MCA – 405 Elective –I (A) Java Programming & Technology
Socket Programming Cal Poly Pomona Young CS380.
NETWORK PROGRAMMING CNET 441
Snippet Engine as a Database Server
Presentation transcript:

Java Sockets Brad Vander Zanden

Agenda What are sockets Client/Server interaction Single client/server example Synchronized data objects Multi-threaded servers Multi-threaded clients Detecting client/server shutdown

Socket One end-point of a two-way communication link between two programs running on the network – Typically one process is called the server – Typically one process is called the client server client portport portport Connection Request list en

Server/Client Interaction (from Jonathan Engelsma’s Java Sockets Tutorial-- Sockets Tutorial-- Client Server Processing Synchronization Point Communication

Single Client/Server Example echo client – try with resources only works for Java 1.7 or later – hydra machines have Java 1.6 (4/2014)

Synchronized Data Objects Client Server Processing Synchronization Point Communication

Synchronized Data Objects KnockKnock Server Example WAITING ANOTHER SENTKNOCK KNOCK SENTCLUE serve “KnockKnock” Who’s There? Serve Clue Not Who’s There serve “Knock Knock” Input matches Clue + “who” serve answer + “Want another?” Input does not match Clue + “who” Serve “Try again. KnockKnock” No Yes Serve “Bye” serve “KnockKnock”

Multi-Threaded Servers Multi-Threaded KnockKnock Example

Multi-Threaded Client Chat Example Client

Multi-Threaded Client (Pseudo Code) Main Thread New Socket Get SocketRead and SocketWrite objects Create WriteConsoleThread w/ SocketRead obj While (more Stdin) Process/Write to SocketWrite Obj WriteConsoleThread While (more Socket Read Obj) Process line Write to console

Detecting client/server shutdown Occurs when socket read object returns null – Socket.close() on other end does not signal other process of termination Server thread: Exit while loop, wrap up processing, and terminate

Multi-Threaded Client (Detecting Shutdown) Main Thread New Socket interrupted = false Get SocketRead and SocketWrite objects Create WriteConsoleThread w/ SocketRead obj While (more Stdin) if (interrupted) break Process/Write to SocketWrite Obj WriteConsoleThread While (more Socket Read Obj) Process line Write to console Notify Main thread of server shutdown by setting interrupted to true