The document discusses keyboard and file access in Java using input streams, readers, and buffers. It then covers socket programming in Java to connect to other computers over a network. A client-server model is described where the client connects to the server, which listens for connections on a port. The server accepts the connection and a separate socket is used to communicate with that client.
The document discusses socket programming and provides an overview of client-server applications using sockets. It describes how sockets allow for interprocess communication using the client-server model. The key steps for creating TCP and UDP client and server applications in both C and Java programming languages are outlined, including how to create sockets, bind sockets, connect sockets, send and receive data. Code examples of a TCP client and server application written in C are also provided.
This document provides an overview of Java sockets including how they allow for client-server communication over networks, the lifecycle of a socket server, and code examples for a socket server and clients. It discusses how sockets provide connection-oriented and connectionless services in Java using classes like ServerSocket and Socket. Diagrams depict the use cases and classes for a socket server that handles weather requests from multiple clients. Code for a WeatherSocketServer class and examples of client requests are also included.
This document provides an overview of socket programming in Java. It discusses how client-server applications use sockets to communicate over a network. Sockets are identified by an IP address and port number. The document explains TCP and UDP socket programming in Java. For TCP, it describes how the server creates a welcoming socket to accept client connections. For both TCP and UDP, it outlines the basic interactions between client and server sockets. The document concludes by noting that socket programming is easy in Java and real-time applications typically use threads to handle each socket.
The document discusses network programming with sockets. It outlines basic socket programming concepts like client-server models, TCP and UDP services, and BSD sockets. It then describes key socket functions for creation and setup, establishing connections, sending/receiving data, and tearing down connections.
This document provides an overview of socket programming in Java. It defines a socket as an endpoint for two-way communication between programs over a network. The key classes for socket programming in Java are Socket for clients and ServerSocket for servers. It describes how to establish connections between clients and servers using these classes, set up input and output streams, and properly close connections. TCP sockets provide reliable, ordered connections while UDP sockets are unreliable and unordered. Exceptions that can occur during network programming are also listed.
Socket programming in Java allows applications to communicate over the internet. Sockets are endpoints for communication that are identified by an IP address and port number. A socket connection is established between a client and server socket. The server creates a welcoming socket to accept client connection requests, then a separate connection socket to communicate with that client. Data can be sent bidirectionally over the connected sockets as input/output streams. UDP uses datagram sockets without a connection, requiring the explicit destination address on each message.
The document discusses socket programming and provides an overview of client-server applications using sockets. It describes how sockets allow for interprocess communication using the client-server model. The key steps for creating TCP and UDP client and server applications in both C and Java programming languages are outlined, including how to create sockets, bind sockets, connect sockets, send and receive data. Code examples of a TCP client and server application written in C are also provided.
This document provides an overview of Java sockets including how they allow for client-server communication over networks, the lifecycle of a socket server, and code examples for a socket server and clients. It discusses how sockets provide connection-oriented and connectionless services in Java using classes like ServerSocket and Socket. Diagrams depict the use cases and classes for a socket server that handles weather requests from multiple clients. Code for a WeatherSocketServer class and examples of client requests are also included.
This document provides an overview of socket programming in Java. It discusses how client-server applications use sockets to communicate over a network. Sockets are identified by an IP address and port number. The document explains TCP and UDP socket programming in Java. For TCP, it describes how the server creates a welcoming socket to accept client connections. For both TCP and UDP, it outlines the basic interactions between client and server sockets. The document concludes by noting that socket programming is easy in Java and real-time applications typically use threads to handle each socket.
The document discusses network programming with sockets. It outlines basic socket programming concepts like client-server models, TCP and UDP services, and BSD sockets. It then describes key socket functions for creation and setup, establishing connections, sending/receiving data, and tearing down connections.
This document provides an overview of socket programming in Java. It defines a socket as an endpoint for two-way communication between programs over a network. The key classes for socket programming in Java are Socket for clients and ServerSocket for servers. It describes how to establish connections between clients and servers using these classes, set up input and output streams, and properly close connections. TCP sockets provide reliable, ordered connections while UDP sockets are unreliable and unordered. Exceptions that can occur during network programming are also listed.
Socket programming in Java allows applications to communicate over the internet. Sockets are endpoints for communication that are identified by an IP address and port number. A socket connection is established between a client and server socket. The server creates a welcoming socket to accept client connection requests, then a separate connection socket to communicate with that client. Data can be sent bidirectionally over the connected sockets as input/output streams. UDP uses datagram sockets without a connection, requiring the explicit destination address on each message.
The document discusses network programming and Java sockets. It introduces elements of client-server computing including networking basics like TCP, UDP and ports. It then covers Java sockets, explaining how to implement both a server and client using Java sockets. Code examples are provided of a simple server and client. The conclusion emphasizes that Java makes socket programming easier than other languages like C.
This is all about socket programming in java using TCP and UDP socket and an example of simple Echo Server.
Also includes concepts of the socket, Socket class and methods and use of those.
This document discusses Java networking and client/server communication. A client machine makes requests to a server machine over a network using protocols like TCP and UDP. TCP provides reliable data transmission while UDP sends independent data packets. Port numbers map incoming data to running processes. Sockets provide an interface for programming networks, with ServerSocket and Socket classes in Java. A server program listens on a port for client connections and exchanges data through input/output streams. Servlets extend web server functionality by executing Java programs in response to client requests.
Socket programming uses a client-server model where the client initiates contact with the server to request a service. It uses sockets to allow two processes to communicate by sending and receiving data through the socket. The socket API provides functions to create, bind, listen for, accept, and communicate over sockets. It defines sockets as endpoints for communication between processes running on the same or different devices on a network.
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
Application Layer and Socket Programmingelliando dias
The document discusses computer networking concepts related to the application layer and socket programming. It provides an overview of client-server applications and protocols, and describes how sockets allow applications to communicate over TCP and UDP. Specifically, it explains how servers can use sockets, binding, listening and accepting to establish TCP connections with clients. It also explains how clients can use sockets and connecting to communicate with servers. For UDP, it describes how servers can use sockets and binding to receive datagrams, while clients can use sockets and sending to communicate with servers.
This document discusses socket programming in Java. It begins by defining what a socket is - the combination of an IP address and port number used to uniquely identify an endpoint in a network connection. It then covers the basics of client-server socket programming using both TCP and UDP, including creating and using sockets, streams, and datagrams. Example code is provided for both TCP and UDP client and server implementations in Java using sockets to send and receive data. The document concludes with references for more information on socket programming.
This document discusses socket programming concepts in Java including server-client communication using sockets, the InetAddress class and its methods like getLocalHost(), getByName(), and getAllByName(), and the Socket and ServerSocket classes. It provides code examples to demonstrate how to use these classes and methods to establish connections between a client and server and exchange data over the network.
Sockets allow for two-way communication between hosts in a network. There are two types of sockets: server sockets and client sockets. Server sockets wait for connection requests from clients, while client sockets are used to send and receive data from servers. Sockets provide input and output streams for transmission of data between endpoints.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
This document provides an overview of networking concepts in Java including:
1) It outlines topics on networking basics like IP addresses, ports, protocols and client-server interactions.
2) It describes how to write networking clients and servers using sockets.
3) It provides an example of writing a simple ICQ client-server application to demonstrate sockets.
4) It discusses communicating with web servers by retrieving and sending information using URLs and URLConnections.
This document discusses client-server programming and socket programming. It begins by explaining the client-server model, where the client initiates contact with the server to request a service. It then covers application layer programming using sockets as the interface. Sockets provide an abstraction for network communication, representing an endpoint. The document outlines functions for creating, binding, listening for connections, accepting connections, and sending/receiving data with sockets. It also discusses related topics like network byte order, utility functions, and address data structures.
Introduction
This Tutorial is On Socket Programming In C Language for Linux. Instructions Give Below will only work On Linux System not in windows.
Socket API In windows is called Winsock and there we can discuss about that in another tutorial.
What is Socket?
Sockets are a method for communication between a client program and a server program in a network.
A socket is defined as "the endpoint in a connection." Sockets are created and used with a set of programming requests or "function calls" sometimes called the sockets application programming interface (API).
The most common sockets API is the Berkeley UNIX C interface for sockets.
Sockets can also be used for communication between processes within the same computer.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
The document describes 8 programs related to networking in Java. Program 1 obtains the IP address of a website. Program 2 connects to the home page of yahoo.com and displays the HTML. Program 3 parses a URL into its components. Program 4 translates between IP addresses and host names. Program 5 prints all IP addresses of a domain. Program 6 obtains the local machine's IP address. Program 7 finds the host name given an IP address. Program 8 downloads a file from the web and saves or displays it. The last part describes a client-server program with a server that echoes back a string sent by the client.
The document discusses sockets and the client-server model for interprocess communication. It describes what sockets are, the different types of sockets (STREAM, DATAGRAM, RAW), and how they are used for reliable and unreliable communication between processes. It provides code examples for creating, connecting, sending, receiving and closing sockets in both client and server applications using TCP and UDP. Key system calls for sockets like socket(), bind(), listen(), accept(), connect(), send(), recv(), close() are also explained.
This document discusses sockets programming in Java. It covers server sockets, which listen for incoming client connections, and client sockets, which connect to servers. It describes how to create server and client sockets in Java using the ServerSocket and Socket classes. Examples are provided of simple Java programs to implement a TCP/IP server and client using sockets.
When we desire a communication between two applications possibly running on different machines, we need sockets. This presentation aims to provide knowledge of basic socket programming to undergraduate students. Basically, this presentation gives the importance of socket in the area of networking and Unix Programming. The presentation of Topic (Sockets) has designed according to the Network Programming Subject, B.Tech, 6th Semester syllabus of Punjab Technical University Kapurthala, Punjab.
Socket programming allows applications on networked computers to communicate reliably using TCP or unreliably using UDP. A socket represents an open connection between two endpoints and has methods to get input/output streams, the remote host/port, and local port. A client socket connects to a server, while a server socket listens on a port and accepts connections from clients.
The document discusses WebSocket in Java, including:
1. WebSocket is a protocol providing full-duplex communications over a single TCP connection and was standardized by IETF as RFC 6455.
2. Sample WebSocket applications are demonstrated using the JavaWebSocket library, Java EE 7 with Tomcat, and Spring 4 with SockJS for fallback support to older browsers.
3. Code snippets show how to set up WebSocket servers and handlers in each approach to handle connections, messages, and disconnections from clients.
The document describes what various people and groups are doing using the present continuous tense. It asks questions about the activities of Barack Obama, Cristiano, and others, and answers whether they are studying, dancing, playing soccer, eating, cooking, swimming, drinking water, or running based on videos. The questions and answers help to illustrate uses of the present continuous tense in English.
The document discusses network programming and Java sockets. It introduces elements of client-server computing including networking basics like TCP, UDP and ports. It then covers Java sockets, explaining how to implement both a server and client using Java sockets. Code examples are provided of a simple server and client. The conclusion emphasizes that Java makes socket programming easier than other languages like C.
This is all about socket programming in java using TCP and UDP socket and an example of simple Echo Server.
Also includes concepts of the socket, Socket class and methods and use of those.
This document discusses Java networking and client/server communication. A client machine makes requests to a server machine over a network using protocols like TCP and UDP. TCP provides reliable data transmission while UDP sends independent data packets. Port numbers map incoming data to running processes. Sockets provide an interface for programming networks, with ServerSocket and Socket classes in Java. A server program listens on a port for client connections and exchanges data through input/output streams. Servlets extend web server functionality by executing Java programs in response to client requests.
Socket programming uses a client-server model where the client initiates contact with the server to request a service. It uses sockets to allow two processes to communicate by sending and receiving data through the socket. The socket API provides functions to create, bind, listen for, accept, and communicate over sockets. It defines sockets as endpoints for communication between processes running on the same or different devices on a network.
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
Application Layer and Socket Programmingelliando dias
The document discusses computer networking concepts related to the application layer and socket programming. It provides an overview of client-server applications and protocols, and describes how sockets allow applications to communicate over TCP and UDP. Specifically, it explains how servers can use sockets, binding, listening and accepting to establish TCP connections with clients. It also explains how clients can use sockets and connecting to communicate with servers. For UDP, it describes how servers can use sockets and binding to receive datagrams, while clients can use sockets and sending to communicate with servers.
This document discusses socket programming in Java. It begins by defining what a socket is - the combination of an IP address and port number used to uniquely identify an endpoint in a network connection. It then covers the basics of client-server socket programming using both TCP and UDP, including creating and using sockets, streams, and datagrams. Example code is provided for both TCP and UDP client and server implementations in Java using sockets to send and receive data. The document concludes with references for more information on socket programming.
This document discusses socket programming concepts in Java including server-client communication using sockets, the InetAddress class and its methods like getLocalHost(), getByName(), and getAllByName(), and the Socket and ServerSocket classes. It provides code examples to demonstrate how to use these classes and methods to establish connections between a client and server and exchange data over the network.
Sockets allow for two-way communication between hosts in a network. There are two types of sockets: server sockets and client sockets. Server sockets wait for connection requests from clients, while client sockets are used to send and receive data from servers. Sockets provide input and output streams for transmission of data between endpoints.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
This document provides an overview of networking concepts in Java including:
1) It outlines topics on networking basics like IP addresses, ports, protocols and client-server interactions.
2) It describes how to write networking clients and servers using sockets.
3) It provides an example of writing a simple ICQ client-server application to demonstrate sockets.
4) It discusses communicating with web servers by retrieving and sending information using URLs and URLConnections.
This document discusses client-server programming and socket programming. It begins by explaining the client-server model, where the client initiates contact with the server to request a service. It then covers application layer programming using sockets as the interface. Sockets provide an abstraction for network communication, representing an endpoint. The document outlines functions for creating, binding, listening for connections, accepting connections, and sending/receiving data with sockets. It also discusses related topics like network byte order, utility functions, and address data structures.
Introduction
This Tutorial is On Socket Programming In C Language for Linux. Instructions Give Below will only work On Linux System not in windows.
Socket API In windows is called Winsock and there we can discuss about that in another tutorial.
What is Socket?
Sockets are a method for communication between a client program and a server program in a network.
A socket is defined as "the endpoint in a connection." Sockets are created and used with a set of programming requests or "function calls" sometimes called the sockets application programming interface (API).
The most common sockets API is the Berkeley UNIX C interface for sockets.
Sockets can also be used for communication between processes within the same computer.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
The document describes 8 programs related to networking in Java. Program 1 obtains the IP address of a website. Program 2 connects to the home page of yahoo.com and displays the HTML. Program 3 parses a URL into its components. Program 4 translates between IP addresses and host names. Program 5 prints all IP addresses of a domain. Program 6 obtains the local machine's IP address. Program 7 finds the host name given an IP address. Program 8 downloads a file from the web and saves or displays it. The last part describes a client-server program with a server that echoes back a string sent by the client.
The document discusses sockets and the client-server model for interprocess communication. It describes what sockets are, the different types of sockets (STREAM, DATAGRAM, RAW), and how they are used for reliable and unreliable communication between processes. It provides code examples for creating, connecting, sending, receiving and closing sockets in both client and server applications using TCP and UDP. Key system calls for sockets like socket(), bind(), listen(), accept(), connect(), send(), recv(), close() are also explained.
This document discusses sockets programming in Java. It covers server sockets, which listen for incoming client connections, and client sockets, which connect to servers. It describes how to create server and client sockets in Java using the ServerSocket and Socket classes. Examples are provided of simple Java programs to implement a TCP/IP server and client using sockets.
When we desire a communication between two applications possibly running on different machines, we need sockets. This presentation aims to provide knowledge of basic socket programming to undergraduate students. Basically, this presentation gives the importance of socket in the area of networking and Unix Programming. The presentation of Topic (Sockets) has designed according to the Network Programming Subject, B.Tech, 6th Semester syllabus of Punjab Technical University Kapurthala, Punjab.
Socket programming allows applications on networked computers to communicate reliably using TCP or unreliably using UDP. A socket represents an open connection between two endpoints and has methods to get input/output streams, the remote host/port, and local port. A client socket connects to a server, while a server socket listens on a port and accepts connections from clients.
The document discusses WebSocket in Java, including:
1. WebSocket is a protocol providing full-duplex communications over a single TCP connection and was standardized by IETF as RFC 6455.
2. Sample WebSocket applications are demonstrated using the JavaWebSocket library, Java EE 7 with Tomcat, and Spring 4 with SockJS for fallback support to older browsers.
3. Code snippets show how to set up WebSocket servers and handlers in each approach to handle connections, messages, and disconnections from clients.
The document describes what various people and groups are doing using the present continuous tense. It asks questions about the activities of Barack Obama, Cristiano, and others, and answers whether they are studying, dancing, playing soccer, eating, cooking, swimming, drinking water, or running based on videos. The questions and answers help to illustrate uses of the present continuous tense in English.
Introduces bookmarking collection, a GC algorithm that works with the virtual memory manager to eliminate paging. Just before memory is paged out, the collector "bookmarks" the targets of pointers from the pages. Using these bookmarks, BC can perform full garbage collections without loading the pages back from disk. By performing in-memory garbage collections, BC can speed up Java programs by orders of magnitude (up to 41X).
The document provides a brief overview of several locations and organizations in Copenhagen, Denmark, including Øksnehallen, Forsamling which hosts activities through DGI, the historic City Hall building designed by Martin Nyrop and finished in 1905, and that the document encourages open connections.
Open and online: connections, community and reality Catherine Cronin
Slides for Open Education Week webinar by Catherine Cronin & Sheila McNeill, hosted by the University of Sussex.
Webinar recording available here: https://connectpro.sussex.ac.uk/p96542464/
A multithreaded program allows two or more parts of the same program, called threads, to run concurrently. Each thread defines a separate path of execution and threads are lightweight processes that can run independently and share resources such as memory. The document discusses thread creation in Java using the Thread class and Runnable interface, thread life cycle and states, thread priorities, synchronization, and interthread communication using wait(), notify(), and notifyAll() methods.
Presentiaon task sheduling first come first serve FCFSAhmed Salah
This document discusses the First Come First Served (FCFS) CPU scheduling algorithm. FCFS is a non-preemptive algorithm that allocates the CPU to the process that requests it first. It is simple to implement using a first-in first-out queue, but it is not optimal and can result in longer waiting times for shorter processes. While easy to understand, FCFS is not suitable for time-sharing systems due to its non-preemptive nature.
Download some lyrical love! A beautiful story of love between my youngest son Andy's toy puppies - 'Sandy' and 'Jess', set to the music 'Look of Love' by Dusty Springfield
ASCII is a 7-bit character encoding standard used to represent English text that defines 128 characters including 95 printable characters and 33 non-printing control characters. It was developed by ANSI and while it can only encode basic English text, ASCII was almost universally supported and could represent each character with a single byte, making it important for early digital communication.
Computer programmers developed coding systems to represent letters, numbers, and symbols with numeric codes. Three popular coding systems are EBCDIC, ASCII, and Unicode. EBCDIC used 6-bit codes and could represent 64 symbols, while ASCII is now most common and uses 8-bit codes for 256 symbols. Unicode is an evolving worldwide standard that uses 16-bit codes to represent over 65,000 symbols and characters from different languages.
Process' Virtual Address Space in GNU/LinuxVarun Mahajan
The document discusses the virtual address space of a process in GNU/Linux. It explains that a process has both a user space and kernel space in virtual memory. The process' virtual address space contains text, data, and shared library segments. Functions like brk, sbrk, mmap, malloc, and free are used to allocate and free memory in the data segment to grow the process heap.
C-SCAN scheduling is a variant of SCAN scheduling that is designed to provide uniform wait times. Like SCAN, C-SCAN moves the disk head from one end of the disk to the other, servicing requests along the way. When it reaches the end, it immediately returns to the beginning without servicing additional requests, treating the cylinders as a circular list.
Java Performance Fundamental 세미나 교재입니다. 3장은 Garbage Collection에 대해 설명하고 있습니다. 먼저 JVM에서 사용하는 Garbage Collection 뿐만 아니라 일반적인 Garbage Collection의 Algorithm을 상세히 알아봅니다. 그 후 Hotspot JVM의 Heap구조와 Garbage Collector를 설명하고 Generation별로 어떻게 동작하는 지에 대해 설명합니다. 이어 IBM JVM에 대한 Heap 구조와 Garbage Collector에 대해서도 설명합니다.
* Garbage Collection 이란?
* Garbage Collection 의 대상
* Garbage Collection 의 기본 Algorithm
* Hotspot JVM의 Garbage Collection
o Serial Collector
o Incremental Collector
o Parallel Collector
o CMS Collector
o Parallel Compaction Collector
o Garbage First Collector
* IBM JVM의 Garbage Collection
o Optimize for Throughput Collector
o Optimize for Pause Time Collector
o Generational Concurrent Collector
o Subpool Collector
Paging is a memory management technique that retrieves data from secondary storage in same-sized blocks called pages. It allows the physical address space of a process to be noncontiguous. When a program needs data from secondary storage, a page fault occurs and the operating system loads the required page into memory. Common page replacement algorithms are page stealing and pre-cleaning. Address translation architecture divides the address generated by the CPU into a page number and page offset.
The document discusses the LOOK and C-LOOK disk scheduling algorithms. It explains that LOOK scheduling moves the disk arm only as far as the final request in each direction before reversing, rather than scanning the full disk. An example is provided to illustrate LOOK scheduling. The advantages of LOOK over SCAN are better head movement, while the disadvantage is non-uniform waiting times. C-LOOK is described as a version of C-SCAN that provides better head movement.
The document discusses three disk scheduling algorithms: SSTF, SCAN, and C-SCAN. SSTF stands for Shortest Seek Time First and services requests based on minimizing seek time. SCAN and C-SCAN are variations that improve on FCFS by serving requests in a single direction around the disk to reduce seek time. C-SCAN additionally ensures uniform wait times for requests.
The document discusses several basic garbage collection techniques, including reference counting, mark-sweep collection, mark-compact collection, and copying garbage collection. Reference counting fails to reclaim circular structures and has overhead when pointers are created or destroyed. Mark-sweep identifies live objects but leaves memory fragmented, while mark-compact compacts objects after marking to reduce fragmentation. Copying garbage collection divides memory into two semispaces and copies live objects between them when one semispace fills up.
The document discusses the First Come First Serve (FCFS) disk scheduling algorithm. FCFS is the simplest disk scheduling algorithm as requests are served in the order they arrive. It is easy to program and intrinsically fair, but does not provide optimal disk head movement as requests are not ordered for proximity. The document provides an example of the FCFS algorithm applied to a disk request queue, showing the path the disk head takes to fulfill the requests and the total head movement distance.
The document discusses various design issues related to interprocess communication using message passing. It covers topics like synchronization methods, buffering strategies, process addressing schemes, reliability in message passing, and group communication. The key synchronization methods are blocking and non-blocking sends/receives. Issues addressed include blocking forever if the receiving process crashes, buffering strategies like null, single-message and finite buffers, and naming schemes like explicit and implicit addressing. Reliability is achieved using protocols like four-message, three-message and two-message. Group communication supports one-to-many, many-to-one and many-to-many communication with primitives for multicast, membership and different ordering semantics.
Packages allow organization of classes and import statements. Package statements declare the package a class belongs to and import statements allow referring to classes in other packages. The compiler uses package and import statements to find classes.
Reader and writer classes provide character-based input/output and are built upon stream classes. FileReader and FileWriter allow reading and writing of character files but performance can be improved by wrapping them in buffered classes like BufferedReader and BufferedWriter. PrintWriter is also commonly used for writing and provides additional functionality.
Packages allow organization of classes and import statements. Package statements declare the package a file belongs to while import statements allow referring to classes from other packages without their fully qualified names. The compiler searches jar files and the classpath to locate classes.
Multithreading allows concurrent execution through threads which are lightweight subtasks that run within a process. Creating a thread can be done by extending Thread class and overriding run() or implementing Runnable interface. Threads make programs scalable and allow asynchronous event-driven programming.
Java I/O uses streams for sequential input/output. Reader/Writer classes provide character-based I/O. File and filter streams provide access to files. Buffered streams improve performance of unbuffered streams
This document provides an overview of Java input-output (I/O) streams and classes. It discusses the core stream classes like InputStream, OutputStream, Reader, Writer and their subclasses like FileInputStream, FileOutputStream, FileReader, FileWriter. It also covers buffered stream classes like BufferedInputStream, BufferedOutputStream, BufferedReader, BufferedWriter which provide better performance. Examples are given to demonstrate reading, writing and file handling using these stream classes.
This document provides an overview of Java input/output programming, networking, and streams. It discusses reading input from the console and keyboard using BufferedReader, StringTokenizer, and Scanner. It also covers writing output to the console. Predefined streams like System.in and System.out are explained. The basics of character streams, byte streams, and Java streams are summarized. Networking concepts like IP addresses that enable communication between devices on a computer network are also briefly introduced.
forwarder.java.txt java forwarder class waits for an in.docxbudbarber38650
forwarder.java.txt
// java forwarder class
// waits for an inbound connection A on port INPORT
// when it is received, it launches a connection B to <OUTHOST,OUTPORT>
// and creates threads to read-B-write-A and read-A-write-B.
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
class forwarder {
public static String OUTHOST;
public static InetAddress OUTDEST;
public static short OUTPORT = 22;
public static short INPORT = 2345;
public static boolean DEBUG = true;
public static void main(String[] v) {
// get command-line parameters
if (v.length < 3) {
System.err.println("args: inport outhost outport");
return;
}
INPORT = (short)(new Integer(v[0])).intValue();
OUTHOST = v[1];
OUTPORT = (short)(new Integer(v[2])).intValue();
// DNS lookup, done just once!
System.err.print("Looking up address of " + OUTHOST + "...");
try {
OUTDEST = InetAddress.getByName(OUTHOST);
}
catch (UnknownHostException uhe) {
System.err.println("unknown host: " + OUTHOST);
return;
}
System.err.println(" got it!");
// initialize LISTENER socket
// wait for connection
ServerSocket ss = null;
ss = new ServerSocket(INPORT);// needs try-catch
Socket s1;
while(true) { // accept loop
s1 = ss.accept();// needs try-catch
// now set up the second connection from here to <OUTDEST,OUTPORT>,
// represented by a second socket s2
// Then create the two Copier instances, as described in the
// project description, and start() the two threads.
// At that point, this main loop simply continues
// by going back to the ss.accept() call.
} // accept loop
}// main
/**
* The Copier class handles unidirectional copying from one socket to another.
* You will need to create two of these in the main loop above,
* one for each direction. You create the Copier object, and then
* create and start a Thread object that runs that Copier.
* If c is your Copier instance (created with Copier c = new Copier(sock1, sock2)),
* then the thread is Thread t = new Thread(c), and you start the thread
* with t.start(). Or, in one step, (new Thread(c)).start()
*/
static class Copier implements Runnable {
private Socket _from;
private Socket _to;
public Copier (Socket from, Socket to) {
_from = from;
_to = to;
}
public void run() {
InputStream fis;
OutputStream tos;
try {
fis = _from.getInputStream();
tos = _to.getOutputStream();
} catch (IOException ioe) {
System.err.println("can't get IO streams from sockets");
return;
}
byte[] buf = new byte[2048];
int readsize;
while (true) {
try {
readsize = fis.read(buf);
} catch (IOException ioe) {
break;
}
if (readsize <= 0) break;
try {
tos.write(buf, 0, readsize);
} catch (IOException ioe) {
break;
}
}
// these should be safe close() calls!!
try {
fis.close();
tos.close();
_from.close();
_to.close();
} catch (IOException ioe) {
Syst.
The document discusses various Java I/O streams including input streams, output streams, byte streams, character streams, buffered streams, properties class, print stream, file locking, serialization and print writer class. It provides examples of reading and writing files using FileInputStream, FileOutputStream, FileReader, FileWriter and other stream classes. Methods of different stream classes are also explained along with their usage.
The document discusses Java streams and I/O. It defines streams as abstract representations of input/output devices that are sources or destinations of data. It describes byte and character streams, the core stream classes in java.io, predefined System streams, common stream subclasses, reading/writing files and binary data with byte streams, and reading/writing characters with character streams. It also covers object serialization/deserialization and compressing files with GZIP.
The document discusses different types of sockets in Java network programming:
- TCP/IP client socket and TCP/IP server socket are used for reliable, bidirectional stream-based connections between hosts using TCP/IP. The client socket connects to the server socket.
- A Java DatagramSocket class represents a connectionless socket for sending and receiving datagram packets without reliability or sequencing. Commonly used DatagramSocket constructors are described.
- An example program is provided to demonstrate passing a message from a server to a client using sockets, showing the client and server code.
The document discusses input/output files in Java. It covers the key classes used for reading and writing files in Java, including FileInputStream, FileOutputStream, FileReader, and FileWriter. It also discusses byte streams versus character streams, and provides examples of reading and writing to files in Java using these classes. Standard input/output streams like System.in and System.out are also covered.
This document provides an overview of Java input/output (I/O) concepts including reading from and writing to the console, files, and streams. It discusses different I/O stream classes like PrintStream, InputStream, FileReader, FileWriter, BufferedReader, and how to read/write characters, bytes and objects in Java. The document also introduces new I/O features in Java 7 like try-with-resources for automatic resource management.
TCP sockets allow for communication between applications over the internet. A server creates a ServerSocket to listen for incoming connections on a specific port. When a client connects, the server accepts the connection to get a Socket. Both client and server then obtain input and output streams from the Socket to send and receive data. The connection is closed once communication is complete. Multithreading allows servers to handle multiple clients concurrently by spawning a new thread for each connection.
This document discusses network programming clients. It begins by defining clients and servers, explaining that clients initiate connections by specifying a host and port, while servers listen on a port without specifying a host. It then provides the basic steps for implementing a generic network client in Java: creating a socket, input and output streams, performing I/O, and closing the socket. Additional topics covered include parsing strings with StringTokenizer, an example client that verifies email addresses, and a MailAddress class to parse email addresses.
This document discusses creating network clients in Java. It covers creating sockets, implementing a generic network client, parsing data with StringTokenizer, retrieving files from HTTP servers and documents using URL class. It provides code for a generic network client, parsing strings with StringTokenizer, an address verifier client, and classes to retrieve URIs and URLs. It also briefly discusses talking to servers interactively and using the URL class to write a basic web browser.
The document discusses input and output streams in Java. It describes the BufferedReader class, which reads text from a character input stream and buffers it for efficient reading. It also discusses the Scanner class in Java's util package for reading user input through the keyboard. An example program is provided that uses Scanner to read integer and float values from the user and calculate their sum.
File input and output operations in Java are performed using streams. There are two types of streams - byte streams and character streams. Byte streams handle input/output at the byte level while character streams handle input/output at the character level using Unicode encoding. The File class in Java represents files and directories on the filesystem and provides methods to perform operations like creating, reading, updating and deleting files.
This document provides an overview of the Tornado web server and summarizes its internals. It begins with an introduction to Tornado, describing it as a scalable, non-blocking web server and framework written in Python. It then outlines the main Tornado modules and discusses sockets, I/O monitoring using select, poll and epoll, and how Tornado sets up its server loop and handles requests.
The document discusses input and output streams in Java. It provides an overview of character streams, byte streams, and connected streams. It explains how to read from and write to files using FileInputStream, FileOutputStream, FileReader, and FileWriter. It emphasizes the importance of specifying the correct character encoding when working with text files. An example demonstrates reading an image file as bytes, modifying some bytes, and writing the image to a new file.
This document provides an introduction to Java, including:
- Java is an object-oriented language developed by Sun Microsystems in 1991 that is not tied to any particular hardware or operating system.
- It discusses basic Java concepts like objects, classes, inheritance and polymorphism.
- Java applets allow programs written in Java to run within web browsers, and include init(), start(), paint(), stop() and destroy() methods.
- The document also covers client-server programming in Java using sockets, multithreaded programming, servlets, and networking protocols like TCP and UDP.
The document provides information on Java APIs, IO packages, streams, serialization, networking and TCP sockets. It defines that an API allows communication between programs, Java IO handles input/output through streams, and common IO classes include FileInputStream, FileOutputStream. Networking concepts covered include sockets, ports, IP addresses and protocols like TCP. TCP sockets in Java use Socket and ServerSocket classes.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Best 20 SEO Techniques To Improve Website Visibility In SERPPixlogix Infotech
Boost your website's visibility with proven SEO techniques! Our latest blog dives into essential strategies to enhance your online presence, increase traffic, and rank higher on search engines. From keyword optimization to quality content creation, learn how to make your site stand out in the crowded digital landscape. Discover actionable tips and expert insights to elevate your SEO game.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
In the rapidly evolving landscape of technologies, XML continues to play a vital role in structuring, storing, and transporting data across diverse systems. The recent advancements in artificial intelligence (AI) present new methodologies for enhancing XML development workflows, introducing efficiency, automation, and intelligent capabilities. This presentation will outline the scope and perspective of utilizing AI in XML development. The potential benefits and the possible pitfalls will be highlighted, providing a balanced view of the subject.
We will explore the capabilities of AI in understanding XML markup languages and autonomously creating structured XML content. Additionally, we will examine the capacity of AI to enrich plain text with appropriate XML markup. Practical examples and methodological guidelines will be provided to elucidate how AI can be effectively prompted to interpret and generate accurate XML markup.
Further emphasis will be placed on the role of AI in developing XSLT, or schemas such as XSD and Schematron. We will address the techniques and strategies adopted to create prompts for generating code, explaining code, or refactoring the code, and the results achieved.
The discussion will extend to how AI can be used to transform XML content. In particular, the focus will be on the use of AI XPath extension functions in XSLT, Schematron, Schematron Quick Fixes, or for XML content refactoring.
The presentation aims to deliver a comprehensive overview of AI usage in XML development, providing attendees with the necessary knowledge to make informed decisions. Whether you’re at the early stages of adopting AI or considering integrating it in advanced XML development, this presentation will cover all levels of expertise.
By highlighting the potential advantages and challenges of integrating AI with XML development tools and languages, the presentation seeks to inspire thoughtful conversation around the future of XML development. We’ll not only delve into the technical aspects of AI-powered XML development but also discuss practical implications and possible future directions.
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/building-and-scaling-ai-applications-with-the-nx-ai-manager-a-presentation-from-network-optix/
Robin van Emden, Senior Director of Data Science at Network Optix, presents the “Building and Scaling AI Applications with the Nx AI Manager,” tutorial at the May 2024 Embedded Vision Summit.
In this presentation, van Emden covers the basics of scaling edge AI solutions using the Nx tool kit. He emphasizes the process of developing AI models and deploying them globally. He also showcases the conversion of AI models and the creation of effective edge AI pipelines, with a focus on pre-processing, model conversion, selecting the appropriate inference engine for the target hardware and post-processing.
van Emden shows how Nx can simplify the developer’s life and facilitate a rapid transition from concept to production-ready applications.He provides valuable insights into developing scalable and efficient edge AI solutions, with a strong focus on practical implementation.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Driving Business Innovation: Latest Generative AI Advancements & Success StorySafe Software
Are you ready to revolutionize how you handle data? Join us for a webinar where we’ll bring you up to speed with the latest advancements in Generative AI technology and discover how leveraging FME with tools from giants like Google Gemini, Amazon, and Microsoft OpenAI can supercharge your workflow efficiency.
During the hour, we’ll take you through:
Guest Speaker Segment with Hannah Barrington: Dive into the world of dynamic real estate marketing with Hannah, the Marketing Manager at Workspace Group. Hear firsthand how their team generates engaging descriptions for thousands of office units by integrating diverse data sources—from PDF floorplans to web pages—using FME transformers, like OpenAIVisionConnector and AnthropicVisionConnector. This use case will show you how GenAI can streamline content creation for marketing across the board.
Ollama Use Case: Learn how Scenario Specialist Dmitri Bagh has utilized Ollama within FME to input data, create custom models, and enhance security protocols. This segment will include demos to illustrate the full capabilities of FME in AI-driven processes.
Custom AI Models: Discover how to leverage FME to build personalized AI models using your data. Whether it’s populating a model with local data for added security or integrating public AI tools, find out how FME facilitates a versatile and secure approach to AI.
We’ll wrap up with a live Q&A session where you can engage with our experts on your specific use cases, and learn more about optimizing your data workflows with AI.
This webinar is ideal for professionals seeking to harness the power of AI within their data management systems while ensuring high levels of customization and security. Whether you're a novice or an expert, gain actionable insights and strategies to elevate your data processes. Join us to see how FME and AI can revolutionize how you work with data!
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
How to Get CNIC Information System with Paksim Ga.pptxdanishmna97
Pakdata Cf is a groundbreaking system designed to streamline and facilitate access to CNIC information. This innovative platform leverages advanced technology to provide users with efficient and secure access to their CNIC details.
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceIndexBug
Imagine a world where machines not only perform tasks but also learn, adapt, and make decisions. This is the promise of Artificial Intelligence (AI), a technology that's not just enhancing our lives but revolutionizing entire industries.
Building Production Ready Search Pipelines with Spark and MilvusZilliz
Spark is the widely used ETL tool for processing, indexing and ingesting data to serving stack for search. Milvus is the production-ready open-source vector database. In this talk we will show how to use Spark to process unstructured data to extract vector representations, and push the vectors to Milvus vector database for search serving.
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc
How does your privacy program stack up against your peers? What challenges are privacy teams tackling and prioritizing in 2024?
In the fifth annual Global Privacy Benchmarks Survey, we asked over 1,800 global privacy professionals and business executives to share their perspectives on the current state of privacy inside and outside of their organizations. This year’s report focused on emerging areas of importance for privacy and compliance professionals, including considerations and implications of Artificial Intelligence (AI) technologies, building brand trust, and different approaches for achieving higher privacy competence scores.
See how organizational priorities and strategic approaches to data security and privacy are evolving around the globe.
This webinar will review:
- The top 10 privacy insights from the fifth annual Global Privacy Benchmarks Survey
- The top challenges for privacy leaders, practitioners, and organizations in 2024
- Key themes to consider in developing and maintaining your privacy program
Programming Foundation Models with DSPy - Meetup SlidesZilliz
Prompting language models is hard, while programming language models is easy. In this talk, I will discuss the state-of-the-art framework DSPy for programming foundation models with its powerful optimizers and runtime constraint system.
“An Outlook of the Ongoing and Future Relationship between Blockchain Technologies and Process-aware Information Systems.” Invited talk at the joint workshop on Blockchain for Information Systems (BC4IS) and Blockchain for Trusted Data Sharing (B4TDS), co-located with with the 36th International Conference on Advanced Information Systems Engineering (CAiSE), 3 June 2024, Limassol, Cyprus.
2. Keyboard Access in Java
• Java provides access to the standard input stream
(stdin)
• java.lang.System.in
– ‘java.lang is the package
– ‘System’ is the class
– ‘in’ is an object of type InputStream
– InputStream is defined in the java.io package
3. Keyboard Access in Java
int cc;
While(true) {
try {
cc=System.in.read();
} catch (IOException ex) {}
System.out.write(cc);
}
4. java.io.InputStreamReader
• This class provides a character interface to input
stream (also converts to unicode characters)
int cc;
InputStreamReader inkey;
Inkey=new InputStreamReader(System.in);
While(true) {
try {
cc = inkey.read();
} catch (IOException ex) {}
System.out.print(cc);
}
5. java.io.BufferedReader
• Provides a buffer for the input stream—can be
accessed on a line by line basis
String s;
InputStreamReader inkey;
BufferedReader bufkey;
inkey=new InputStreamReader(System.in);
bufkey=new BufferedReader(inkey);
While(true) {
s=bufkey.readLine();
System.out.println(s);
}
6. Lines of text
(strings)
java.io.BufferedReader
Unicode character
stream
java.io.InputStreamReader
Byte stream from
keyboard
java.lang.System.in
Keyboard
7. File access in Java
• java.io.File
– This allows you to open a file
– Eg. File infile = new File(“Blah.txt”);
• java.io.FileInputStream
– This sets up an input stream from the file
• FileInputStream instream = new
FileInputStream(infile);
– FileInputStream can open a file directly…
• FileInputStream instream = new
FileInputStream(“Blah.txt”);
8. File access in Java
FileInputStream instream;
instream = new FileInputStream(“blah.txt”)
int cc;
while ((cc=instream.read() != -1) {
System.out.print((char)cc);
}
9. File Access in Java
• FileInputStream is a subclass of InputStream.
• Recall that the System.in object, used for
keyboard input is also of class InputStream.
• This means that we can use InputStreamReader
and BufferedReader just as with the keyboard
13. My uppercase code
Lines of text
(strings)
java.io.Bufferedreader
Unicode character
stream
java.io.InputStreamReader
Byte stream from
file
java.file.FileInputStream
File
14. The process of using a file
Open file using some
unique identifier
Read and write to
and from the file
Close the file
15. Accessing a computer across a
network
Connect to computer
using some unique
identifier
Read and write to
and from the computer
Close the connection
16. Sockets - connecting to other
computers
• When connecting to another computer you use a
‘socket’.
– analogous to a ‘file handle’ used when accessing
files
– When opening a file you uniquely identify it by its
file name. When connecting to a computer you
uniquely identify it with its IP number
17. Addressing Computers
• An IP number is four numbers (each between 0
and 255) separated by a ‘.’ Eg. Goblin’s IP is
130.217.208.41
– However, because numbers are difficult to remember,
the network provides a service that associates names
with numbers.
• Eg goblin.cs.waikato.ac.nz : 130.217.208.41
18. Ports — connecting to programs on
other computers over a network
• Using a unique number we can identify a
computer to connect to
– However, computers have many programs running
on them
– We identify which program to communicate with by
using a port number
– Common networking programs (such as telnet, ftp
and WWW services) are always on the same port.
These ports are called “well known”
– Telnet is on port 23, FTP on port 21, WWW
services are on port 80, etc.
20. Sockets in Java
• Java’s networking facilities are provided in the java.net
package
– To make a connection to another machine we must first know
its IP number—this is done by the InetAddress class
• InetAddress goblinsIP = InetAddress.getByName(“goblin”);
– Now we can open a socket
• Socket mysocket = new Socket(goblinsIP, 23);
– This would connect to the telnet port on goblin
21. Sockets in Java
• The following methods return input and output streams that you
can use to read and write to the socket, just like a file
• mysocket.getInputStream();
• Mysocket.getOutputStream();
– Eg:
• InputStreamReader in = new
InputStreamReader(mysocket.getInputStream());
• OutputStreamWriter out = new
OutputStreamWriter(mysocket.getOutputStream());
22. Echoed response
Lines of text
(strings)
java.io.BufferedReader
Unicode character
stream
java.io.InputStreamReader
Byte stream from
socket
java.net.Socket
Network
23. Echo Client
• There is a program (also known as a service) on most networked
machines that echoes back what you write to it. This program
connects to that echo service (port 7) and writes and reads to/from it
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String [] args)
throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
24. Echo Client...
try {
InetAddress goblinsIP =
InetAddress.getByName(“goblin”);
echoSocket =
new Socket(goblinsIP, 7);
out = new PrintWriter(echoSocket.
getOutputStream(), true);
in = new BufferedReader(new
InputStreamReader(echoSocket.
getInputStream());
25. Echo Client
} catch (UnknownHostException e) {
System.err.println(“Don’t know about “
+”host: goblin.”);
System.exit(1);
} catch (IOException e) {
System.err.println(“Couldn’t get I/O “
+”for connection to: goblin.”);
System.exit(1);
}
27. Echo Client in use.
mhall@goblin:~> java EchoClient
Boo!
echo: Boo!
Hello there
echo: Hello there
Quit
echo: Quit
28. Clients and Servers…
• So far we have considered a ‘client’ program
that connects through a socket to a service (or
server)
Connect
Write
Read
Close
29. Clients and Servers…
• Consider the actions of the server at the other
end
Listen
Accept
Read
Write
Close
30. Clients and Servers…
• Java provides the class ServerSocket which listens to
connections. Eg:
– ServerSocket myserver = new ServerSocket(4420);
– This sets up a ServerSocket to listen on port 4420
– Now wait for a connection using the “accept” method. This
method returns a reference to a regular socket that can be
used to read and write to the connection client
– Socket theClient = myserver.accept();
– The socket “theClient” can now be used tp read and write to
the connecting client in the usual way
31. Echo Server…
import java.io.*;
import java.net.*;
public class EchoServer {
public static void main(String [] args)
throws IOException {
ServerSocket myserver = null;
try {
myserver = new ServerSocket(4444);
} catch (IOException e) {
System.out.println(“Could not listen “
+”on port: 4444.”);
System.exit(1);
}
32. Echo Server...
Socket theclient = null;
try {
theclient = myserver.accept();
} catch (IOException e) {
System.err.pritnln(“Accept failed.”);
System.exit(1);
}
PrintWriter out = new
PrintWriter(theclient.getOutputStream(),
true));
BufferedReader in = new
BufferedReader(new
InputStreamReader(theclient.
getInputStream()));
34. Request for connection
ServerSocket Client Program
ServerSocket
creates socket
Socket Socket
Port 23 Port X
Request for
Network connection
35. Server and Client Communicate
Server Program Client Program
ServerSocket
Socket Socket
Port 23 Port X
Network
36. Multiple Connections…
• Consider the case where multiple clients are
connected to the same service. Eg. Multiple
telnet connections to goblin
• How do sockets deal with this?
37. Request for Connection
ServerSocket
ServerSocket allocates a new
socket
New Socket
Port 23
Request for
connection from
client
38. Request for Another Connection
Server code
ServerSocket
allocates another
ServerSocket
socket
New Socket Established
Socket
Port 23
Another request for Client reads and
connection writes to server
39. Multiple Connections...
•The port records what clients have connected and
diverts interaction to the appropriate socket.
•A client is identified by:
– IP number and Port number!
•When a socket is created on the client machine it is
allocated a local port number as well. This is the port
that the server uses to write to the client