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.
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.
1. Sockets provide a connection between client and server programs that allows them to communicate over a network. A socket is bound to each end of the connection.
2. The Socket class implements client sockets and allows a client program to connect to a server, send and receive data, and close the connection. The ServerSocket class allows a server program to listen for connections on a port and accept sockets from clients.
3. When a client connects to a server, the server accepts the connection using ServerSocket and returns a Socket. The client and server can then communicate by getting input and output streams from the socket to send data over the connection according to the network protocol.
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
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
The InetAddress class in Java represents IP addresses and allows conversion between host names and IP addresses. It has subclasses for IPv4 (Inet4Address) and IPv6 (Inet6Address) addresses. InetAddress objects store both the raw IP address and associated host name. Methods are provided to look up addresses by name, check address properties like scope, and test address reachability. Caching is used to improve performance of name lookups.
Java Network Programming getting started, Getting Started with java network programming, two tier architecture, java client server programming, core java, java to standard edition, core java, Introduction to network programming in java
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.
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.
1. Sockets provide a connection between client and server programs that allows them to communicate over a network. A socket is bound to each end of the connection.
2. The Socket class implements client sockets and allows a client program to connect to a server, send and receive data, and close the connection. The ServerSocket class allows a server program to listen for connections on a port and accept sockets from clients.
3. When a client connects to a server, the server accepts the connection using ServerSocket and returns a Socket. The client and server can then communicate by getting input and output streams from the socket to send data over the connection according to the network protocol.
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
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
The InetAddress class in Java represents IP addresses and allows conversion between host names and IP addresses. It has subclasses for IPv4 (Inet4Address) and IPv6 (Inet6Address) addresses. InetAddress objects store both the raw IP address and associated host name. Methods are provided to look up addresses by name, check address properties like scope, and test address reachability. Caching is used to improve performance of name lookups.
Java Network Programming getting started, Getting Started with java network programming, two tier architecture, java client server programming, core java, java to standard edition, core java, Introduction to network programming in java
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.
This document provides an overview of client-server networking concepts in Java. It discusses elements like network basics, ports and sockets. It explains how to implement both TCP and UDP clients and servers in Java using socket classes. Sample code is provided for an echo client-server application using TCP and a quote client-server application using UDP. Exception handling for sockets is also demonstrated.
The document discusses network programming in Java using the java.net package. It covers using TCP and UDP for network communication. TCP provides reliable, ordered streams between hosts using sockets, while UDP provides simpler datagram transmission that is unreliable but can be broadcast. The InetAddress class represents IP addresses, and sockets are used for both TCP clients/servers and UDP communication.
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 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.
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.
Java- Datagram Socket class & Datagram Packet classRuchi Maurya
Java DatagramSocket and DatagramPacket
Java DatagramSocket and DatagramPacket classes are used for connection-less socket programming.
________________________________________
Java DatagramSocket class
Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets.
A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.
Commonly used Constructors of DatagramSocket class
o DatagramSocket() throws SocketEeption: it creates a datagram socket and binds it with the available Port Number on the localhost machine.
o DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number.
o DatagramSocket(int port, InetAddress address) throws SocketEeption: it creates a datagram socket and binds it with the specified port number and host address.
________________________________________
Java DatagramPacket class
Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in any order. Additionally, packet delivery is not guaranteed.
Commonly used Constructors of DatagramPacket class
o DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to receive the packets.
o DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram packet. This constructor is used to send the packets.
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.
The document outlines a course on Java networking consisting of 8 modules. Module 7 discusses basic networking concepts like TCP, UDP, and port numbers. It then covers Java sockets for both client-server programming and passing objects over the network. Code examples are provided for a simple socket server and client, and for a server and client that pass a Customer object. The module concludes with an example of reading a URL using Java.
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 discusses TCP/IP networking concepts in Java like sockets, datagrams, ports and protocols. It provides code examples for socket programming in Java using TCP for client-server applications and UDP for datagram transmissions. It also recommends books that cover Java networking topics in more detail.
This document discusses network programming and Java sockets. It begins with an introduction to client-server computing and networking basics like TCP, UDP, and ports. It then covers Java sockets in detail, including how to implement a server that can accept multiple clients by creating a new thread for each, and how to implement a client. Sample code is provided for a simple single-threaded server and client. The document concludes that programming client-server applications in Java using sockets is easier than in other languages like C.
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.
This document discusses Java networking and the client-server model. It explains that Java socket programming allows sharing of data between devices using protocols like TCP and UDP. Sockets are bound to port numbers to identify applications. The client-server model involves clients sending requests and servers sending responses. Examples of Java code for a simple client and server are also provided.
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.
This document describes a multiplayer Java game that uses stream sockets to allow two players to play from separate computers. The game has a server that maintains the game state and connects two client players. Stream sockets provide a connection-oriented service using TCP. The game framework includes classes for the game board, players, and the server that runs the main game logic and waits for client connections. Players are represented as client sockets that maintain their own GUI and can place marks on the shared game board by communicating with the server.
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.
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 document contains source code for several Java programs that demonstrate concepts related to networking and URLs. The programs cover topics like retrieving a URL, getting URL information, working with InetAddress, demonstrating parts of a URL, and connectionless and connection-oriented communication between a server and client using UDP and TCP sockets. The code examples are accompanied by expected output.
This document provides an overview of client-server networking concepts in Java. It discusses elements like network basics, ports and sockets. It explains how to implement both TCP and UDP clients and servers in Java using socket classes. Sample code is provided for an echo client-server application using TCP and a quote client-server application using UDP. Exception handling for sockets is also demonstrated.
The document discusses network programming in Java using the java.net package. It covers using TCP and UDP for network communication. TCP provides reliable, ordered streams between hosts using sockets, while UDP provides simpler datagram transmission that is unreliable but can be broadcast. The InetAddress class represents IP addresses, and sockets are used for both TCP clients/servers and UDP communication.
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 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.
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.
Java- Datagram Socket class & Datagram Packet classRuchi Maurya
Java DatagramSocket and DatagramPacket
Java DatagramSocket and DatagramPacket classes are used for connection-less socket programming.
________________________________________
Java DatagramSocket class
Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets.
A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.
Commonly used Constructors of DatagramSocket class
o DatagramSocket() throws SocketEeption: it creates a datagram socket and binds it with the available Port Number on the localhost machine.
o DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number.
o DatagramSocket(int port, InetAddress address) throws SocketEeption: it creates a datagram socket and binds it with the specified port number and host address.
________________________________________
Java DatagramPacket class
Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in any order. Additionally, packet delivery is not guaranteed.
Commonly used Constructors of DatagramPacket class
o DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to receive the packets.
o DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram packet. This constructor is used to send the packets.
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.
The document outlines a course on Java networking consisting of 8 modules. Module 7 discusses basic networking concepts like TCP, UDP, and port numbers. It then covers Java sockets for both client-server programming and passing objects over the network. Code examples are provided for a simple socket server and client, and for a server and client that pass a Customer object. The module concludes with an example of reading a URL using Java.
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 discusses TCP/IP networking concepts in Java like sockets, datagrams, ports and protocols. It provides code examples for socket programming in Java using TCP for client-server applications and UDP for datagram transmissions. It also recommends books that cover Java networking topics in more detail.
This document discusses network programming and Java sockets. It begins with an introduction to client-server computing and networking basics like TCP, UDP, and ports. It then covers Java sockets in detail, including how to implement a server that can accept multiple clients by creating a new thread for each, and how to implement a client. Sample code is provided for a simple single-threaded server and client. The document concludes that programming client-server applications in Java using sockets is easier than in other languages like C.
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.
This document discusses Java networking and the client-server model. It explains that Java socket programming allows sharing of data between devices using protocols like TCP and UDP. Sockets are bound to port numbers to identify applications. The client-server model involves clients sending requests and servers sending responses. Examples of Java code for a simple client and server are also provided.
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.
This document describes a multiplayer Java game that uses stream sockets to allow two players to play from separate computers. The game has a server that maintains the game state and connects two client players. Stream sockets provide a connection-oriented service using TCP. The game framework includes classes for the game board, players, and the server that runs the main game logic and waits for client connections. Players are represented as client sockets that maintain their own GUI and can place marks on the shared game board by communicating with the server.
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.
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 document contains source code for several Java programs that demonstrate concepts related to networking and URLs. The programs cover topics like retrieving a URL, getting URL information, working with InetAddress, demonstrating parts of a URL, and connectionless and connection-oriented communication between a server and client using UDP and TCP sockets. The code examples are accompanied by expected output.
The document contains a lab manual for computer networks that lists various experiments to be conducted. It includes experiments on socket programming, TCP and UDP communication using one-way and two-way protocols, file transfer using TCP, sliding window protocols, broadcasting, checksum calculations, routing algorithms, and remote method invocation. The experiments are scheduled to take place between December 2012 to February 2013. The lab manual provides details of each experiment such as its aim, algorithm, source code, and expected output.
The document discusses Java UDP sockets and networking. It explains how to use the InetAddress class to represent IP addresses, and the DatagramSocket and DatagramPacket classes to send and receive UDP datagrams. It provides code examples for both client and server implementations of UDP networking in Java using these classes.
The document discusses testing in Android applications. It recommends moving as much logic as possible to the Java Virtual Machine (JVM) to allow for easier unit testing. This includes business logic, models, and network code using Retrofit. It also suggests using Espresso for UI testing on Android and monkeyrunner for basic OS interaction testing. The document acknowledges testing on Android can be painful due to speed and fragmentation issues, and proposes compromises like helping quality assurance engineers with tools like the Bee library.
The document describes 5 Java programming experiments related to database access and web applications:
1. A program that accesses a table from an MS Access database.
2. A similar program that accesses a table from a Derby database.
3. A program that implements remote method invocation using an interface.
4. A simple servlet program that outputs HTML.
5. A servlet program that connects to a Derby database and outputs records.
This document provides code for implementing remote method invocation (RMI) between a client and server in Java. It includes code for the interface, server, and client. The interface defines the remote method. The server implements the interface and exports the remote object. It registers the object with the RMI registry. The client looks up the remote object from the registry and invokes the remote method on the server. The client and server communicate over RMI to call the method remotely.
This document discusses networking and data access in Eqela. It covers topics like TCP/IP sockets, DNS, HTTP clients, and databases. For networking, it describes how to create sockets, resolve hostnames, connect to servers, and send/receive data over TCP, UDP, and HTTP. For data access, it explains how to open databases like SQLite, perform queries, and integrate other SQL databases. It also notes considerations for connecting to databases from mobile devices like using an intermediate gateway service over HTTP.
The document discusses associating discussions from communication repositories with source code files. It describes past approaches like change log analysis, information retrieval, and lightweight textual analysis. The objective of the study is to find these associations between discussions and source code using fuzzy code search to link code fragments in discussions to source code.
This document discusses network programming in Java. It shows how to get the local host address and address of google.com. It defines a server as a program that listens on a TCP port for connections and a client as a program that initiates connections. It demonstrates how to create a server socket to listen on a port and how a client socket can connect to an IP address and port. It also discusses Java I/O streams for input and output and how to handle files in Java including checking if a directory exists, creating it if not, opening output streams to write to files, and approaches for reading from files.
The document describes a Java program that simulates DNS using UDP sockets. It includes algorithms for getting frame size from the user, creating and sending frames to the server from the client, and the server sending ACK/NACK signals. The program code provided implements a UDP DNS server that receives host requests, looks up IPs in a hardcoded array, and responds to clients. It also implements a UDP DNS client that takes user input, sends requests to the server, and displays the IP response.
- JavaMail API provides a way to send and receive emails in Java through core classes like Session, Message, InternetAddress, and Transport. It supports SMTP, POP3, and IMAP protocols.
- To send an email, create a Message, set the from/to addresses, and use Transport to send it through an SMTP server. To receive emails, use a POP3 or IMAP store to access messages in a mailbox folder.
- Attachments, HTML content, authentication, and searching emails are also supported through the API classes. Other providers extend JavaMail for features like NNTP and S/MIME encryption.
The document appears to be a lab report submitted by a student for their Network Programming lab course. It includes 13 experiments performed on topics like writing echo programs using TCP and UDP, creating a client-server chat program, file transfer programs, and remote command execution. For each experiment, the student has provided the code for the client and server sides to demonstrate how to complete the task. The report is submitted to their professor and includes their name, course codes, semester and year details.
The document provides code examples for several Java programming concepts:
1. A program that takes command line arguments, calculates the sum and average of the numbers passed, and displays the results.
2. A Student class with member functions to read and display student details like name and age.
3. A Square class with data members for length, area, and perimeter, and member functions to read, compute values, and display details.
The document contains 10 additional examples covering topics like inheritance, packages, exceptions, threads, and GUI programming.
Java networking allows connecting computing devices to share resources using sockets and protocols. Key concepts include IP addresses and port numbers to identify devices, connection-oriented protocols like TCP for reliability, and connectionless protocols like UDP for speed. The Socket class represents an endpoint for communication between applications, while the ServerSocket class allows creating a server to accept client connections. URL and URI classes handle uniform resource locators and identifiers to access resources on the internet.
This document discusses socket programming in Java. It begins by explaining the key classes for socket programming - InetAddress, Socket, ServerSocket, DatagramSocket, DatagramPacket, and MulticastSocket. It then provides examples of TCP client-server applications using Sockets and ServerSockets, UDP client-server applications using DatagramSockets and DatagramPackets, and multicast applications using MulticastSockets. The examples demonstrate how to send and receive data over sockets in both text and binary formats.
The document discusses networking concepts in Java like InetAddress, URL, and URLConnection. It provides code examples to look up the IP address and hostname for a given URL, get details of a URL like protocol, port number etc., and retrieve content from a URLConnection. It explains how to use these classes to work with network resources in Java programs.
The document discusses socket programming in Java. It covers key concepts like layers of protocols, ports, the client-server model, and socket classes. Example code is provided to demonstrate how to create simple client and server applications using sockets to connect two processes and exchange data between them. The examples show how to bind sockets, send/receive data over input/output streams, and handle multiple concurrent connections by spawning new threads.
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.
Similar to Java networking programs socket based (20)
The Elphinstonian 1988-College Building Centenary Number (2).pdfMukesh Tekwani
This is the 1988 issue of The Elphinstonian, the annual magazine of Elphinstone College, Mumbai. This is the special issue to commemorate the Century of the Elphinstone College Building in Mumbai.
This document contains lecture notes on various topics related to gravitation and orbital mechanics:
1. It defines Newton's law of gravitation and the gravitational constant G.
2. It discusses the difference between G and g, the acceleration due to gravity, and derives the relation between the two.
3. It then covers concepts like the critical velocity, time period, binding energy, and escape velocity required for a satellite to orbit or escape the gravitational pull of Earth.
4. Additional topics include weightlessness in satellites, variation of g with altitude and depth, and the definition of latitude.
ISCE-Class 12-Question Bank - Electrostatics - PhysicsMukesh Tekwani
This is a 14 page question bank on the chapters of Electrostatics. This is based on the syllabus of most Board exams such as CBSE, ISCE and state boards.
Extremely important topic for Digital electronics, digital circuits, computer architecture and computer science.
Full video is available on Youtube: https://youtu.be/oyOaXqx06pY
This video explains the method of converting a decimal number to a binary number. Many solved examples are given here and also two exercises which you can attempt on your own and then check the answers.
I have also discussed the concept of LSB (least significant bit) and MSB (most significant bit), and also least significant digit (LSD) and most significant digit (MSD).
This topic is important for following courses: class 11 and 12 computer science of all state boards, class 11 and 12 physics, BSc Computer science, BSc IT, MCA (Masters degree in Computer Applications), BTech, BE (First Year), and many competitive examinations.
Free Lectures on YouTube for IGCSE Physics for the syllabus effective 2020-21. These lectures cover the syllabus of IGCSE and a major part of GCSE syllabus also.
1. The Hidden Meaning of Words in Science Question Papers
2. Scientific Notation or Powers of Ten Notation
3. Units and Base Quantities
4. What is Physics?
Refraction and dispersion of light through a prismMukesh Tekwani
This document contains 20 important theory questions about refraction and dispersion of light through a prism. Some key topics covered are:
1) The angle of deviation of light passing through a prism depends on factors like the refracting angle of the prism and the angle of incidence of light.
2) When white light passes through a prism, it disperses into its constituent colors due to the refractive index of the material being different for different wavelengths of light.
3) In the position of minimum deviation, the angles of incidence and refraction of a monochromatic light ray passing through a prism are related to the refracting angle of the prism.
This document contains important theory questions about refraction of light at a plane surface and total internal reflection. It includes 24 multiple choice and derivation questions covering topics such as Snell's law, refractive index, critical angle, total internal reflection, mirages, reflecting prisms, reversing prisms, erecting prisms, optical fibers, and their applications. The document was prepared by Mukesh N Tekwani and provides a comprehensive review of key concepts and formulas relating to the refraction and total internal reflection of light.
This document contains 10 important theory questions about spherical mirrors. It defines key terms used to describe spherical mirrors such as pole, center of curvature, radius of curvature, principal axis, aperture, principal focus, focal length and focal plane. It also derives several important relationships for spherical mirrors, including that the focal length of a concave or convex mirror of small aperture is half the radius of curvature, and the mirror formula relating the focal length to the object and image distances. Finally, it derives the magnification formula for concave mirrors and asks which type of spherical mirror is preferable for observing traffic from a car.
Atom, origin of spectra Bohr's theory of hydrogen atomMukesh Tekwani
This document contains 15 important theory questions about Rutherford's alpha particle scattering experiment, Rutherford's model of the atom, its limitations, Bohr's model of the hydrogen atom, Bohr's postulates, expressions for the stationary and kinetic energy levels of an electron in the hydrogen atom, the energy level diagram for hydrogen showing different emission series, and definitions of terms like Rydberg constant, excitation potential, and ionization potential. The questions are related to key experiments and models in the development of atomic structure and spectra.
Refraction of light at spherical surfaces of lensesMukesh Tekwani
This document contains 15 important theory questions about refraction of light at spherical surfaces and lenses. It includes questions about sign convention in optics, the optical center of a lens, focal length of concave and convex lenses, lens maker's formula, derivation of expressions for refraction at single spherical surfaces and thin lens combinations, linear magnification by a lens, location of a virtual image formed by a convex lens based on focal length, dependence of focal length on wavelength, definition and unit of power of a lens, definition of 1 dioptre, formula for combined power of two lenses in contact, and laws governing image formation by lenses. The questions cover key concepts like derivation, definition, diagrams, formulas, and image formation.
This document outlines the unit-wise weightage for the February 2020 ISCE Class 12 Physics board exam. Unit 3 on Magnetic Effects of Current and Magnetism has the highest weightage at 16. Other highly weighted units include Electromagnetic Induction and Alternating Currents at 14, and Optics at 12. The lowest weighted units are Communication Systems at 2 and Electronic Devices at 8.
What is Cyber Law? Why is cyber security law needed? International cyber law. What is copyright? What are security, controls, privacy, piracy and ethics? Code of ethics for computer professionals. What is cyber insurance?
The document discusses the disadvantages of HTML and the advantages of using XML instead. It notes that HTML lacks structure, syntax checking, and is not suitable for data interchange or describing semantics. XML was designed to store, describe, and transport data, unlike HTML which was designed for display. XML simplifies data sharing and transport between applications since it separates data from presentation and uses plain text. It also allows for international character support and makes data more available and reusable.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
1. Java – Networking Page 1
Java – Networking
PROGRAMS
Program 1: Write a program that obtains the IP address of a site.
/* Program to find the IP address of a website */
// Mukesh N Tekwani
import java.io.*;
import java.net.*;
class AddressDemo
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter a website name: ");
String site = br.readLine();
try
{
InetAddress ip = InetAddress.getByName(site);
System.out.print("The IP address is: " + ip);
}
catch(UnknownHostException e)
{
System.out.println("WebSite not found");
}
}
}
/* Output:
C:JavaPrgs>java AddressDemo
Enter a website name: www.google.com
The IP address is: www.google.com/74.125.235.50
*/
Modification:
Modify the above program so that it takes the website name (e.g., http://www.yahoo.com) from the
command line. If the website address is not given at command line, use the default address
http://www.google.com.
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
2. 2 Java - Networking
Program 2: Write a program that connects to the home page of www.yahoo.com (read
from a URL).
//Program to connect to the home page of www.yahoo.com
// Mukesh N Tekwani
import java.net.*;
import java.io.*;
public class URLReader
{
public static void main(String[] args) throws Exception
{
URL myurl = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(new
InputStreamReader(myurl.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
Output:
When this program is run, it displays the complete HTML code of the web page.
Possible Error: If we give site address simply as www.yahoo.com, we get MalformedURLException.
The protocol http must also be given in the complete URL.
Modification:
Modify the above program so that it takes the website name (e.g., http://www.yahoo.com) from the
command line. If the website address is not given at command line, use the default address
http://www.google.com.
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
3. Java - Networking Page 3
Program 3: Write a program that parses a URL address into its components.
//Program to parse a URL address into its components
// Mukesh N Tekwani
import java.net.*;
import java.io.*;
public class ParseAddress
{
public static void main (String[] args)
{
if (args.length !=1)
{
System.out.println ("Error: missing url argument");
System.out.println ("Usage: java ParseURL <url>");
System.exit (0);
}
try
{
URL siteurl = new URL (args[0]);
System.out.println ("Protocol = " +
siteurl.getProtocol ());
System.out.println("Host = " + siteurl.getHost ());
System.out.println("File name= " + siteurl.getFile());
System.out.println("Port = " + siteurl.getPort ());
System.out.println("Target = " + siteurl.getRef ());
}
catch (MalformedURLException e)
{
System.out.println ("Bad URL = " + args[0]);
}
} // main
} // class ParseAddress
Output:
C:JavaPrgs>java ParseAddress http://www.microsoft.com
Protocol = http
Host = www.microsoft.com
File name =
Port = -1
Target = null
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
4. 4 Java - Networking
Program 4: Write a program to translate an IP address into host name or a host name to
an IP address.
// Translate IP address to hostname or vice-versa
// Mukesh N Tekwani
import java.net.*;
import java.io.*;
class TranslateAddress
{
public static void main (String args[])
{
if (args.length != 1)
{
System.out.println ("Error! No IP or host name
address");
System.out.println ("Usage: java TranslateAddress
java.sun.com");
System.out.println (" or java TranslateAddress
209.249.116.143");
System.exit (0);
}
try
{
// When the argument passed is a host name(e.g.
// sun.com), the corresponding IP address is returned.
// If passed an IP address, then only the IP address
// is returned.
InetAddress ipadd = InetAddress.getByName (args[0]);
System.out.println ("Address " + args[0] + " = " +
ipadd);
// To get the hostname when passed an IP address use
// getHostName (), which will return the host name
// string.
System.out.println ("Name of " + args[0] + " = " +
ipadd.getHostName ());
}
catch (UnknownHostException e)
{
System.out.println ("Unable to translate the
address.");
}
} // main
} // class TranslateAddress
/* Output:
C:JavaPrgs>java TranslateAddress 130.237.34.133
Address 130.237.34.133 = /130.237.34.133
Name of 130.237.34.133 = ns1.particle.kth.se
*/
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
5. Java - Networking Page 5
Program 5: Write a program to print all the addresses of www.microsoft.com
// Get all IP addresses by name of site
// Mukesh N Tekwani
import java.net.*;
public class AllAddressesOfMicrosoft
{
public static void main (String[] args)
{
try
{
InetAddress[] ipadd =
InetAddress.getAllByName("www.microsoft.com");
for (int i = 0; i < ipadd.length; i++)
{
System.out.println(ipadd[i]);
}
}
catch (UnknownHostException ex)
{
System.out.println("Could not find www.microsoft.com");
}
}
}
/*Output:
C:JavaPrgs>java AllAddressesOfMicrosoft
www.microsoft.com/64.4.31.252
www.microsoft.com/65.55.12.249
www.microsoft.com/65.55.21.250
www.microsoft.com/207.46.131.43
www.microsoft.com/207.46.170.10
www.microsoft.com/207.46.170.123
*/
Modification: Write a program that prints the Internet Address of the local host if we do not
specify any command-line parameters or all Internet addresses of another host if we specify the host
name on the command line.
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
6. 6 Java - Networking
Program 6: Write a program to obtain the IP address of the local machine.
// Find the IP address of the local machine
// Mukesh n Tekwani
import java.net.*;
public class MyOwnAddress
{
public static void main (String[] args)
{
try
{
InetAddress me = InetAddress.getLocalHost();
String myadd = me.getHostAddress();
System.out.println("My address is " + myadd);
}
catch (UnknownHostException e)
{
System.out.println("I'm sorry. I don't know my own
address; really lost!!!.");
}
}
}
/* Output:
C:JavaPrgs>java MyOwnAddress
My address is 192.168.1.7
*/
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
7. Java - Networking Page 7
Program 7: Write a program that accepts an IP address and finds the host name.
// Given the IP address, find the host name
// Mukesh N Tekwani
import java.net.*;
public class ReverseTest
{
public static void main (String[] args)
{
try
{
InetAddress ia =
InetAddress.getByName("65.55.21.250");
System.out.println(ia.getHostName());
System.out.println(ia);
}
catch (Exception e)
{
System.out.println(e);
}
}
}
/* Output:
C:JavaPrgs>java ReverseTest
wwwco1vip.microsoft.com
wwwco1vip.microsoft.com/65.55.21.250
*/
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
8. 8 Java - Networking
Program 8: Write a program to download a file from the Internet and either copy it as a
file on the local machine or display it on the screen.
// Program-download a file & copy it as a file or display it on screen
// Mukesh N Tekwani
import java.io.*;
import java.net.*;
public class DownLoadFile
{
public static void main(String args[])
{
InputStream in = null;
OutputStream out = null;
try
{
if ((args.length != 1) && (args.length != 2))
throw new IllegalArgumentException("Wrong no. of
arguments");
URL siteurl = new URL(args[0]);
in = siteurl.openStream();
if(args.length == 2)
out = new FileOutputStream(args[1]);
else
out = System.out; //display on client machine
byte [] buffer = new byte[4096];
int bytes_read;
while((bytes_read = in.read(buffer)) != -1)
out.write(buffer, 0, bytes_read);
}
catch (Exception ex)
{
System.out.println(ex);
}
finally
{
try
{
in.close(); out.close();
}
catch (Exception ae)
{
System.out.println(ae);
}
}
}
}
/* Output:
C:JavaPrgs>java DownLoadFile http://www.yahoo.com test.txt
*/
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
9. Java - Networking Page 9
CLIENT-SERVER PROGRAMS (Using Sockets)
Client Server
Create TCP Socket Create TCP Socket
Socket cs = new ServerSocket ss = new
Socket(hostname, port); ServerSocket(port);
Client initiates the communication Wait for client connection
by reading the user input Socket listen_socket =
Str = ss.accept();
userinput.readLine(); Then reads the client on listen_socket.
Then sends it to server Server listens client
Server_out.writeBytes(str client_str =
+ ‘n’); client_input.readLine();
Client listens to server using client Server sends reply to client
socket
Close client socket
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
10. 10 Java - Networking
Program 9: Write a client/server program in which a client sends a single string to the
server. The server just displays this string. (Echo)
Server Program:
//Server Program
//Works with file Client1
//Mukesh N Tekwani
import java.io.*;
import java.net.*;
class Server1
{
public static void main(String args[]) throws Exception
{
//create server socket
ServerSocket ss = new ServerSocket(4444);
while (true)
{
Socket listen_socket = ss.accept();
BufferedReader client_input = new BufferedReader(new
InputStreamReader(listen_socket.getInputStream()));
String client_str; //to store string rcvd from client
client_str = client_input.readLine();
System.out.println(client_str);
}
}
}
Client Program:
//Client Program
//Works with file Server1
//Mukesh N Tekwani
import java.io.*;
import java.net.*;
class Client1
{
public static void main(String args[]) throws Exception
{
//create client socket
Socket cs = new Socket("localhost", 4444);
BufferedReader user_input = new BufferedReader(new
InputStreamReader(System.in));
DataOutputStream server_out = new
DataOutputStream(cs.getOutputStream());
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
11. Java - Networking Page 11
String str;
str = user_input.readLine();
server_out.writeBytes(str + 'n');
cs.close();
}
}
Program : Write a TCP/IP client / server program that sends a string in lowercase to the
server which sends the equivalent uppercase string back to the client.
Server Program:
//The server code Server.java:
import java.io.*;
import java.net.*;
public class ServerLower
{
// the socket used by the server
private ServerSocket serverSocket;
ServerLower(int port) // server constructor
{
/* create socket server and wait for connection requests */
try
{
serverSocket = new ServerSocket(port);
System.out.println("Server waiting for client on port " +
serverSocket.getLocalPort());
while(true)
{
Socket socket = serverSocket.accept();
System.out.println("New client asked for a
connection");
TcpThread t = new TcpThread(socket);
System.out.println("Starting a thread for a new
Client");
t.start();
}
}
catch (IOException e)
{
System.out.println("Exception on new ServerSocket:" + e);
}
}
public static void main(String[] arg)
{
new ServerLower(4444);
}
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
12. 12 Java - Networking
/** One instance of this thread will run for each client */
class TcpThread extends Thread
{
Socket socket; // the socket where to listen/talk
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
TcpThread(Socket socket)
{
this.socket = socket;
}
public void run()
{
/* Creating both Data Streams */
System.out.println("Thread trying to create Object
Input/Output Streams");
try
{
// create output first
Soutput = new
ObjectOutputStream(socket.getOutputStream());
Soutput.flush();
Sinput = new
ObjectInputStream(socket.getInputStream());
}
catch (IOException e)
{
System.out.println("Exception creating new
Input/output Streams: " + e);
return;
}
System.out.println("Thread waiting for a String from the
Client");
// read a String (which is an object)
try
{
String str = (String) Sinput.readObject();
str = str.toUpperCase(); //convert lower 2 uppercase
Soutput.writeObject(str);
Soutput.flush();
}
catch (IOException e)
{
System.out.println("Exception reading/writing
Streams: " + e);
return;
}
catch (ClassNotFoundException e1)
{ //nothing needed here
}
finally
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
13. Java - Networking Page 13
{
try
{
Soutput.close();
Sinput.close();
}
catch (Exception e2)
{ //nothing needed here
}
}
}
}
}
Client Program:
//The client code that sends a string in lowercase to the server
import java.net.*;
import java.io.*;
public class ClientLower
{
ObjectInputStream Sinput; // to read the socker
ObjectOutputStream Soutput; // towrite on the socket
Socket socket;
// Constructor connection receiving a socket number
ClientLower(int port)
{
try
{
socket = new Socket("localhost", port);
}
catch(Exception e)
{
System.out.println("Error connectiong to server:" + e);
return;
}
System.out.println("Connection accepted " +
socket.getInetAddress() + ":" + socket.getPort());
/* Creating both Data Streams */
try
{
Sinput = new ObjectInputStream(socket.getInputStream());
Soutput = new
ObjectOutputStream(socket.getOutputStream());
}
catch (IOException e)
{
System.out.println("Exception creating I/O Streams:"+ e);
return;
}
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
14. 14 Java - Networking
String test = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
// send the string to the server
System.out.println("Client sending "" + test + "" to
server");
try
{
Soutput.writeObject(test);
Soutput.flush();
}
catch(IOException e)
{
System.out.println("Error writting to the socket: " + e);
return;
}
// read back the answer from the server
String response;
try
{
response = (String) Sinput.readObject();
System.out.println("Read back from server: " + response);
}
catch(Exception e)
{
System.out.println("Problem reading back from server: " + e);
}
try
{
Sinput.close();
Soutput.close();
}
catch(Exception e)
{ // nothing needed here
}
}
public static void main(String[] arg)
{
new ClientLower(4444);
}
}
Modifications:
1. Modify the Server program in this example so that it is not multithreaded.
2. Modify the client program so that the input string is entered by the user from keyboard when program
runs, instead of storing it within the program.
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
15. Java - Networking Page 15
Program 17:
Write a client-server socket application in which
(i) A client reads a character from the keyboard and sends the character out of its
socket to the server.
(ii) The server reads the character from its connection socket
(iii) The server finds the ASCII value of the character.
(iv) The server sends the ASCII value out of its connection socket to the client.
(v) The client reads the result from its socket and prints the result on its standard
output device.
Server Program:
//Server sends the ASCII code of a character to client
//Mukesh N Tekwani
import java.io.*;
import java.net.*;
class ServerASCII
{
public static void main(String args[]) throws Exception
{
String clientstr, serverstr;
ServerSocket ss = new ServerSocket(4444);
while(true)
{
Socket cs = ss.accept();
System.out.println("Connected to client...");
BufferedReader inFromClient = new BufferedReader(new
InputStreamReader(cs.getInputStream()));
DataOutputStream outToClient = new
DataOutputStream(cs.getOutputStream());
clientstr = inFromClient.readLine();
//read the first character from input
char c = clientstr.charAt(0);
/* Find the ASCII code; note the type casting */
serverstr = "The ASCII code of " + clientstr + " is " +
(int)c + 'n';
outToClient.writeBytes(serverstr);
}
}
}
Output at Client end:
C:JavaPrgs>java ClientASCII
Enter a character
B
From server: The ASCII code of B is 66
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani
16. 16 Java - Networking
PORTS AND SOCKETS
Understanding Ports
Generally speaking, a computer has a single physical connection to the network. All data destined for a
particular computer arrives through that connection. However, the data may be intended for different
applications running on the computer. So how does the computer know to which application to forward the
data? Through the use of ports.
Data transmitted over the Internet is accompanied by addressing information that identifies the computer and
the port for which it is destined. The computer is identified by its 32-bit IP address, which IP uses to deliver
data to the right computer on the network. Ports are identified by a 16-bit number, which TCP and UDP use
to deliver the data to the right application.
In connection-based communication such as TCP, a server application binds a socket to a specific port
number. This has the effect of registering the server with the system to receive all data destined for that port.
A client can then rendezvous with the server at the server's port, as illustrated here:
Definition: The TCP and UDP protocols use ports to map incoming data to a particular process
running on a computer.
In datagram-based communication such as UDP, the datagram packet contains the port number of its
destination and UDP routes the packet to the appropriate application, as illustrated in this figure:
Port numbers range from 0 to 65,535 because ports are represented by 16-bit numbers. The port numbers
ranging from 0 - 1023 are restricted; they are reserved for use by well-known services such as HTTP and FTP
and other system services. These ports are called well-known ports. Your applications should not attempt to
bind to them.
Understanding Sockets
In client-server applications, the server provides some service, such as processing database queries or sending
out current stock prices. The client uses the service provided by the server, either displaying database query
results to the user or making stock purchase recommendations to an investor. The communication that occurs
between the client and the server must be reliable. That is, no data can be dropped and it must arrive on the
client side in the same order in which the server sent it.
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com [Mobile:9869 488 356]
17. Java - Networking Page 17
TCP provides a reliable, point-to-point communication channel that client-server applications on the Internet
use to communicate with each other. To communicate over TCP, a client program and a server program
establish a connection to one another. Each program binds a socket to its end of the connection. To
communicate, the client and the server each reads from and writes to the socket bound to the connection.
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 are used to represent the connection between a client program and a server program. The
java.net package provides two classes--Socket and ServerSocket--that implement the client side of the
connection and the server side of the connection, respectively.
mukeshtekwani@hotmail.com [Mobile:9869 488 356] Prof. Mukesh N. Tekwani