Ruby can be used for both web development and other tasks like CGI programming and as a replacement for PHP. It allows writing web servers, FTP daemons, and more in Ruby. The document discusses how to write basic CGI scripts in Ruby, process forms, create HTML forms, handle cookies and sessions, and send emails with attachments using the Ruby Net::SMTP library. Key methods in the Ruby CGI class are also outlined.
Overview of the JSON-RPC mechanism.
JSON-RPC is a simple RPC (Remote Procedure Call) mechanism, similar to XML-RPC.
Unlike XML-RPC which is a client-server protocol, JSON-RPC is a peer-to-peer protocol.
It uses JSON (Javascript Object Notation, RFC4627) as the serialization format and plain TCP streams or HTTP as transport mechanism.
JSON-RPC defines the three message types Request, Response and Notification. There is no direct mapping of JSON-RPC message to HTTP request. HTTP or plain TCP are merely transport protocols that carry JSON-RPC messages.
JSON-RPC is a simple protocol and therefore lacks most of the features that big web services like SOAP/WSDL and the WS-* standards provide. JSON-RPC may be suited for web service applications with the need for bidirectional interaction (peer2peer), but where the complexity of SOAP is not required.
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.
The document provides an overview of a presentation given by Stephan Schmidt on connecting PHP and JavaScript using JSON-RPC. Some key points:
- It discusses the classic web application model and how business logic resides solely on the server
- With Web 2.0, presentation logic moved to the client but business logic still resides on the server
- The remote proxy pattern can be used to expose server-side business logic as JavaScript objects, making remote calls transparent to the client
- This is done by serializing calls to JSON and making HTTP requests to a JSON-RPC server implemented in PHP
- The server uses reflection to dynamically call the relevant PHP methods and return responses also serialized to JSON
This document provides an overview of server-side and client-side web programming. It discusses common gateway interface (CGI) programs, which allow server-side programs to process HTTP requests and generate HTML responses. CGI programs can access input data sent via forms and output dynamically-generated HTML. Examples demonstrate CGI programs that display fortunes by reading from a file, echo back user input, and look up email addresses in a database. The document also compares JavaScript and Java approaches to client-side scripting.
This document discusses PHP and its suitability for building web services. It covers PHP's evolution as both a server-side and command line tool. It then discusses different architectures and data formats for web services, including RPC, SOAP, REST, JSON and XML. It provides examples of consuming and producing these different service types from PHP.
The document discusses HTTP requests and responses. Some key points:
- HTTP is the most common protocol for web communication. A client sends a request to a server, which returns a response. Requests use methods like GET and POST.
- URLs identify web resources and have components for the protocol, hostname, port, and resource path. Default ports include 80 for HTTP and 443 for HTTPS.
- HTTP requests contain a request line with the method, URI, and version. Headers provide additional information. Responses contain a status line and headers to describe the response.
- HTML forms allow sending request data via GET or POST. GET appends data to the URL while POST sends it in the request body.
This document discusses CGI programming and HTTP cookies. It provides an overview of CGI and how it is used to send data to servers via the GET and POST methods. It also explains how templates can be used to dynamically generate web pages. Finally, it covers HTTP cookies in detail, including how they are delivered, valid parameters for setting cookies, the different types (persistent and non-persistent), and how they are stored on a user's device.
The Hypertext Transfer Protocol (HTTP) is an application layer protocol for distributed, collaborative, hypermedia information systems and is the foundation for data communication on the World Wide Web. HTTP defines methods like GET and POST to indicate the desired action on a resource and uses status codes in responses. It also uses headers in requests and responses to define parameters of the transaction. HTTP typically uses TCP port 80 to allow a client to open a connection and send requests to a server, which responds with messages that may contain requested resources or error information.
Overview of the JSON-RPC mechanism.
JSON-RPC is a simple RPC (Remote Procedure Call) mechanism, similar to XML-RPC.
Unlike XML-RPC which is a client-server protocol, JSON-RPC is a peer-to-peer protocol.
It uses JSON (Javascript Object Notation, RFC4627) as the serialization format and plain TCP streams or HTTP as transport mechanism.
JSON-RPC defines the three message types Request, Response and Notification. There is no direct mapping of JSON-RPC message to HTTP request. HTTP or plain TCP are merely transport protocols that carry JSON-RPC messages.
JSON-RPC is a simple protocol and therefore lacks most of the features that big web services like SOAP/WSDL and the WS-* standards provide. JSON-RPC may be suited for web service applications with the need for bidirectional interaction (peer2peer), but where the complexity of SOAP is not required.
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.
The document provides an overview of a presentation given by Stephan Schmidt on connecting PHP and JavaScript using JSON-RPC. Some key points:
- It discusses the classic web application model and how business logic resides solely on the server
- With Web 2.0, presentation logic moved to the client but business logic still resides on the server
- The remote proxy pattern can be used to expose server-side business logic as JavaScript objects, making remote calls transparent to the client
- This is done by serializing calls to JSON and making HTTP requests to a JSON-RPC server implemented in PHP
- The server uses reflection to dynamically call the relevant PHP methods and return responses also serialized to JSON
This document provides an overview of server-side and client-side web programming. It discusses common gateway interface (CGI) programs, which allow server-side programs to process HTTP requests and generate HTML responses. CGI programs can access input data sent via forms and output dynamically-generated HTML. Examples demonstrate CGI programs that display fortunes by reading from a file, echo back user input, and look up email addresses in a database. The document also compares JavaScript and Java approaches to client-side scripting.
This document discusses PHP and its suitability for building web services. It covers PHP's evolution as both a server-side and command line tool. It then discusses different architectures and data formats for web services, including RPC, SOAP, REST, JSON and XML. It provides examples of consuming and producing these different service types from PHP.
The document discusses HTTP requests and responses. Some key points:
- HTTP is the most common protocol for web communication. A client sends a request to a server, which returns a response. Requests use methods like GET and POST.
- URLs identify web resources and have components for the protocol, hostname, port, and resource path. Default ports include 80 for HTTP and 443 for HTTPS.
- HTTP requests contain a request line with the method, URI, and version. Headers provide additional information. Responses contain a status line and headers to describe the response.
- HTML forms allow sending request data via GET or POST. GET appends data to the URL while POST sends it in the request body.
This document discusses CGI programming and HTTP cookies. It provides an overview of CGI and how it is used to send data to servers via the GET and POST methods. It also explains how templates can be used to dynamically generate web pages. Finally, it covers HTTP cookies in detail, including how they are delivered, valid parameters for setting cookies, the different types (persistent and non-persistent), and how they are stored on a user's device.
The Hypertext Transfer Protocol (HTTP) is an application layer protocol for distributed, collaborative, hypermedia information systems and is the foundation for data communication on the World Wide Web. HTTP defines methods like GET and POST to indicate the desired action on a resource and uses status codes in responses. It also uses headers in requests and responses to define parameters of the transaction. HTTP typically uses TCP port 80 to allow a client to open a connection and send requests to a server, which responds with messages that may contain requested resources or error information.
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.
This document discusses Simple Object Access Protocol (SOAP). SOAP allows applications to exchange information over HTTP and is independent of platform and language. A SOAP message contains an envelope, header, body, and optional fault. The envelope defines the message as SOAP. The header contains application-specific metadata. The body contains the call and response. Fault indicates any errors. SOAP uses HTTP for transport and is XML-based, allowing it to penetrate firewalls.
The document describes how to create a simple web service in Java that returns a greeting message, and then how to test and consume the web service using a client. Key steps include:
1. Creating a Java class with the @WebService annotation to expose a "sayHello" method.
2. Deploying and testing the web service by invoking the "sayHello" method and viewing the request/response messages.
3. Generating a WSDL file from the web service.
4. Creating a client project and using the WSDL to generate a client to invoke the "sayHello" method.
Apache Thrift is a framework for defining and implementing service interfaces and generating code to facilitate remote procedure calls across multiple languages. It handles networking, serialization, and other low-level details, allowing developers to focus on implementing service logic. Services are defined using an interface definition language (IDL) that specifies data types, service methods, and exceptions. The Thrift compiler then generates code to implement clients and servers for the defined services in various languages. On the server side, developers implement handlers that define the logic for each service method. The generated code provides a simple way to deploy the service by connecting the various networking and serialization layers. Many large companies use Thrift for building scalable distributed systems across multiple languages and platforms.
Json-based Service Oriented Architecture for the webkriszyp
The document discusses using JSON and service-oriented architecture (SOA) principles for building client-server applications. It outlines a SOA model with services defined by JSON service mapping descriptions that clients can use to automatically connect to endpoints. It also describes using Dojo to generate services from SMDs and integrate services with Dojo data stores and widgets. RESTful services are supported for full read/write functionality. Comet and offline capabilities are discussed along with security considerations for SOA applications.
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
The document discusses Ajax, which uses a combination of technologies like HTML, JavaScript, XML and CSS to retrieve data from a server asynchronously in the background without interfering with the display and behavior of the existing page. It explains what Ajax is, the technologies used, how it works using XMLHttpRequest object, and provides an example of creating an Ajax request and handling responses from the server. It also touches upon drawbacks and browser compatibility issues with Ajax.
Protocolos de E-mail (SMTP, POP e IMAP)Paulo Bischof
Apresentação realizada no dia 25/10/2013, sobre os protocolos de e-mail, na disciplina de Redes e Sistemas Distribuídos no Centro Universitário Católica de Santa Catarina.
This document provides an introduction to embedding PHP code in HTML documents and sending form data from the client to the server. It discusses using PHP to echo HTML tags and strings. It explains how form data is sent via GET and POST methods and how it can be accessed in the PHP file specified in the form's action using the $_GET, $_POST and $_REQUEST superglobal arrays. It also covers uploading files via HTML forms and accessing file data in the PHP file using the $_FILES array.
CGI (Common Gateway Interface) is an interface that allows a web server to launch external applications dynamically in response to requests. It defines standard communication variables between the web server and CGI programs. CGI programs can be written in any programming language and are executed by the web server to generate dynamic web page content on the fly based on request parameters and structured data. However, CGI has performance and security limitations due to creating new processes for each request.
This document provides information about Python CGI (Common Gateway Interface) programming. It discusses what CGI is, how information is exchanged between a web server and CGI script, and gives an example of a simple "Hello World" Python CGI script. It also covers CGI architecture, configuration, passing data to CGI scripts using GET and POST requests, and handling different HTML form elements like textboxes, checkboxes, radio buttons, and dropdown menus in CGI scripts.
The first of its kind Web Technology Conference on Open Source Technology, WebOSS '07 was organised in Kolkata on Sat, 13th Oct 07 and I spoke at the event as one of the participants on "Building Applications using AJAX". Here I will share my presentation.
A server is a computer that responds to requests from clients like web browsers. Common requests include serving web pages, uploading/downloading files, and sending email. Apache is a popular web server software that runs on 66% of websites. It is feature-rich, efficient, robust, secure, and open source. A port is a software connection between a server and client used to identify the service, like port 80 for HTTP. Servlets are Java programs that extend functionality of web servers. They have advantages over CGI scripts like improved performance from residing in memory.
This document provides an overview and introduction to using PHP with LAMP (Linux, Apache, MySQL, PHP). It discusses what PHP is, why it's useful, and provides a crash course on basic PHP syntax and functions. It also demonstrates how to connect a PHP script to a MySQL database and retrieve data. Finally, it introduces AJAX and the basic steps to make asynchronous JavaScript requests.
This document provides an overview of the history and development of Perl web development, introducing the Common Gateway Interface (CGI) model and its limitations. It describes how mod_perl helped address these issues but lacked portability. The PSGI specification and Plack implementation are presented as a solution, providing a common interface between Perl web applications and web servers. Key aspects of building PSGI applications, such as templates, user input handling, and middleware, are demonstrated. Major frameworks and servers supporting PSGI are also noted.
The document discusses how to develop a simple web service in PHP using the nusoap library in just 5 minutes; it covers the basics of SOAP and implementing a web service that returns city names based on pincodes, handling errors through SOAP faults. The presentation also addresses considerations for SOAP transactions, authentication, and provides additional resources for learning more about SOAP and web services.
This document provides an overview and agenda for a web services tutorial. It discusses consuming and building web services using PHP. The topics that will be covered include: consuming simple web services using file_get_contents, cURL, and Pecl_HTTP; building RESTful and RPC services; handling HTTP requests and responses including status codes, headers, and data formats like JSON and XML; and best practices for versioning, documentation, and statelessness. Code samples are provided on the speaker's website.
Action Mailer allows Rails applications to send and receive emails. It provides configuration options like specifying an SMTP server or delivery method. Email messages can be generated by creating Mailers with methods that define the recipient, subject, body, and other email fields. A controller handles calling these mailer methods to send emails. Views can contain a form to collect email content that gets passed to the controller and used to deliver emails through the mailer.
The document discusses various aspects of working with PHP forms and form data, including:
1) HTML forms use tags like <form> and <input> to collect user data in fields like text boxes and radio buttons. Forms can use GET or POST methods to transmit the data.
2) PHP provides superglobal variables ($_GET, $_POST, $_REQUEST) to access transmitted form data in the backend.
3) It's important to validate form data for security, like checking for required fields and proper email/URL formats. Functions like filter_var() and regular expressions can help validate different field types.
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.
This document discusses Simple Object Access Protocol (SOAP). SOAP allows applications to exchange information over HTTP and is independent of platform and language. A SOAP message contains an envelope, header, body, and optional fault. The envelope defines the message as SOAP. The header contains application-specific metadata. The body contains the call and response. Fault indicates any errors. SOAP uses HTTP for transport and is XML-based, allowing it to penetrate firewalls.
The document describes how to create a simple web service in Java that returns a greeting message, and then how to test and consume the web service using a client. Key steps include:
1. Creating a Java class with the @WebService annotation to expose a "sayHello" method.
2. Deploying and testing the web service by invoking the "sayHello" method and viewing the request/response messages.
3. Generating a WSDL file from the web service.
4. Creating a client project and using the WSDL to generate a client to invoke the "sayHello" method.
Apache Thrift is a framework for defining and implementing service interfaces and generating code to facilitate remote procedure calls across multiple languages. It handles networking, serialization, and other low-level details, allowing developers to focus on implementing service logic. Services are defined using an interface definition language (IDL) that specifies data types, service methods, and exceptions. The Thrift compiler then generates code to implement clients and servers for the defined services in various languages. On the server side, developers implement handlers that define the logic for each service method. The generated code provides a simple way to deploy the service by connecting the various networking and serialization layers. Many large companies use Thrift for building scalable distributed systems across multiple languages and platforms.
Json-based Service Oriented Architecture for the webkriszyp
The document discusses using JSON and service-oriented architecture (SOA) principles for building client-server applications. It outlines a SOA model with services defined by JSON service mapping descriptions that clients can use to automatically connect to endpoints. It also describes using Dojo to generate services from SMDs and integrate services with Dojo data stores and widgets. RESTful services are supported for full read/write functionality. Comet and offline capabilities are discussed along with security considerations for SOA applications.
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
The document discusses Ajax, which uses a combination of technologies like HTML, JavaScript, XML and CSS to retrieve data from a server asynchronously in the background without interfering with the display and behavior of the existing page. It explains what Ajax is, the technologies used, how it works using XMLHttpRequest object, and provides an example of creating an Ajax request and handling responses from the server. It also touches upon drawbacks and browser compatibility issues with Ajax.
Protocolos de E-mail (SMTP, POP e IMAP)Paulo Bischof
Apresentação realizada no dia 25/10/2013, sobre os protocolos de e-mail, na disciplina de Redes e Sistemas Distribuídos no Centro Universitário Católica de Santa Catarina.
This document provides an introduction to embedding PHP code in HTML documents and sending form data from the client to the server. It discusses using PHP to echo HTML tags and strings. It explains how form data is sent via GET and POST methods and how it can be accessed in the PHP file specified in the form's action using the $_GET, $_POST and $_REQUEST superglobal arrays. It also covers uploading files via HTML forms and accessing file data in the PHP file using the $_FILES array.
CGI (Common Gateway Interface) is an interface that allows a web server to launch external applications dynamically in response to requests. It defines standard communication variables between the web server and CGI programs. CGI programs can be written in any programming language and are executed by the web server to generate dynamic web page content on the fly based on request parameters and structured data. However, CGI has performance and security limitations due to creating new processes for each request.
This document provides information about Python CGI (Common Gateway Interface) programming. It discusses what CGI is, how information is exchanged between a web server and CGI script, and gives an example of a simple "Hello World" Python CGI script. It also covers CGI architecture, configuration, passing data to CGI scripts using GET and POST requests, and handling different HTML form elements like textboxes, checkboxes, radio buttons, and dropdown menus in CGI scripts.
The first of its kind Web Technology Conference on Open Source Technology, WebOSS '07 was organised in Kolkata on Sat, 13th Oct 07 and I spoke at the event as one of the participants on "Building Applications using AJAX". Here I will share my presentation.
A server is a computer that responds to requests from clients like web browsers. Common requests include serving web pages, uploading/downloading files, and sending email. Apache is a popular web server software that runs on 66% of websites. It is feature-rich, efficient, robust, secure, and open source. A port is a software connection between a server and client used to identify the service, like port 80 for HTTP. Servlets are Java programs that extend functionality of web servers. They have advantages over CGI scripts like improved performance from residing in memory.
This document provides an overview and introduction to using PHP with LAMP (Linux, Apache, MySQL, PHP). It discusses what PHP is, why it's useful, and provides a crash course on basic PHP syntax and functions. It also demonstrates how to connect a PHP script to a MySQL database and retrieve data. Finally, it introduces AJAX and the basic steps to make asynchronous JavaScript requests.
This document provides an overview of the history and development of Perl web development, introducing the Common Gateway Interface (CGI) model and its limitations. It describes how mod_perl helped address these issues but lacked portability. The PSGI specification and Plack implementation are presented as a solution, providing a common interface between Perl web applications and web servers. Key aspects of building PSGI applications, such as templates, user input handling, and middleware, are demonstrated. Major frameworks and servers supporting PSGI are also noted.
The document discusses how to develop a simple web service in PHP using the nusoap library in just 5 minutes; it covers the basics of SOAP and implementing a web service that returns city names based on pincodes, handling errors through SOAP faults. The presentation also addresses considerations for SOAP transactions, authentication, and provides additional resources for learning more about SOAP and web services.
This document provides an overview and agenda for a web services tutorial. It discusses consuming and building web services using PHP. The topics that will be covered include: consuming simple web services using file_get_contents, cURL, and Pecl_HTTP; building RESTful and RPC services; handling HTTP requests and responses including status codes, headers, and data formats like JSON and XML; and best practices for versioning, documentation, and statelessness. Code samples are provided on the speaker's website.
Action Mailer allows Rails applications to send and receive emails. It provides configuration options like specifying an SMTP server or delivery method. Email messages can be generated by creating Mailers with methods that define the recipient, subject, body, and other email fields. A controller handles calling these mailer methods to send emails. Views can contain a form to collect email content that gets passed to the controller and used to deliver emails through the mailer.
The document discusses various aspects of working with PHP forms and form data, including:
1) HTML forms use tags like <form> and <input> to collect user data in fields like text boxes and radio buttons. Forms can use GET or POST methods to transmit the data.
2) PHP provides superglobal variables ($_GET, $_POST, $_REQUEST) to access transmitted form data in the backend.
3) It's important to validate form data for security, like checking for required fields and proper email/URL formats. Functions like filter_var() and regular expressions can help validate different field types.
This document discusses sending emails using Python's SMTP module. It explains that SMTP is used to send and route emails between servers. The smtplib module defines an SMTP client session object that can be used to send mail. It provides an example of using smtplib to send an email by specifying the sender, receivers, and message. It also shows how to send an HTML email by setting the MIME version, content type, and character set in the message.
This document discusses sending emails using Python's SMTP module. It explains that SMTP is used to send and route emails between servers. The smtplib module defines an SMTP client session object that can be used to send mail. It provides an example of using smtplib to send an email by specifying the sender, receivers, and message. It also describes how to send an HTML email by specifying MIME version, content type, and character set in the message.
The document discusses how to send emails using the Java Mail API. It explains how email works with SMTP, POP, and IMAP protocols. It then outlines the steps to take in Java Mail - creating a mail session, composing the email message by setting properties, recipients, and content, and finally sending the message. Key classes discussed are Session, MimeMessage, InternetAddress, Transport, and Properties.
A web service allows computers to communicate over the web using HTTP and other protocols. It exposes web methods that can be invoked remotely through HTTP requests. Web services use SOAP, HTTP, and other standards to define an interface and exchange data over the web. An example .NET web service demonstrates how web methods are declared and can be tested by calling the service URL in a browser to invoke methods and view response XML.
HTTP is the protocol used to deliver web pages and other resources over the internet. It uses a client-server model, where an HTTP client like a web browser sends requests to an HTTP server, which responds with the requested resources. Requests and responses consist of request/response lines followed by headers and an optional message body. Common request methods are GET and POST, while common response status codes include 200 for success and 404 for "not found". Web servers listen on port 80 by default to receive HTTP requests and send responses. Servlets are Java programs that extend the capabilities of web servers by allowing applications to be executed on the server-side. Servlets provide advantages over CGI scripts like improved performance through caching and platform independence through their Java
The document describes the Tiny Web Server, a simple HTTP server that serves static and dynamic content using the GET method. It parses GET requests, determines if the request is for static or dynamic content, opens and reads the requested file or executes the CGI program, and returns the content along with appropriate HTTP response headers. Key components include parsing the URI to extract the filename and CGI arguments, checking for valid files, and using routines like serve_static() and serve_dynamic() to handle different content types.
This document provides an introduction to PHP, covering topics such as server-side web programming, client/server systems, PHP language basics, syntax, variables, decision making, and interacting with clients. PHP is a server-side scripting language that allows embedding programming code directly into HTML pages. It is interpreted and executed on the server to generate dynamic web page content before being sent to the client. Form data submitted by clients can be accessed on the server through PHP superglobal variables to provide interactive web applications.
This document provides an introduction to PHP, covering topics like server-side web programming, the client-server model, and what PHP is and does. PHP is a server-side scripting language that is interpreted and executed on the server before content is sent to the client. It allows for dynamic content and connecting to databases transparently. The document outlines PHP syntax, variables, constants, operators, decision making, and interacting with HTML forms submitted by clients.
This document provides an introduction to PHP, covering topics like server-side web programming, the client-server model, and what PHP is and how it works. PHP is a server-side scripting language that is interpreted and executed on the server before content is sent to the client. The document outlines PHP language basics like syntax, variables, operators, and control structures. It also discusses how PHP can interact with HTML forms submitted by clients.
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docxkacie8xcheco
Project Assignment 2: Building a Multi-Threaded Web Server
This project assignment is due at the end of the seventh week of the course and is worth 7% of your total grade.
In this project, we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel. Section 2.7 of your text may offer you some insight and help. You should be able to demonstrate that your Web server is capable of delivering your home page to a Web browser.
We are going to implement Version 1.0 of HTTP, as defined in
RFC 1945
, where separate HTTP requests are sent for each component of the Web page. The server will be able to handle multiple simultaneous service requests in parallel. This means that the Web server is multi-threaded. In the main thread, the server listens to a fixed port. When it receives a TCP connection request, it sets up a TCP connection through another port and services the request in a separate thread. To simplify this programming task, we will develop the code in two stages. In the first stage, you will write a multi-threaded server that simply displays the contents of the HTTP request message that it receives. After this program is running properly, you will add the code required to generate an appropriate response.
As you are developing the code, you can test your server from a Web browser. Just remember that you are not serving through the standard port 80, so you need to specify the port number within the URL that you give to your browser. For example, if your machine's name is
host.someschool.edu
, your server is listening to port 6789, and you want to retrieve the file
index.html
, then you would specify the following URL within the browser:
http://host.someschool.edu:6789/index.html
If you omit ":6789," the browser will assume port 80, which most likely will not have a server listening on it.
When the server encounters an error, it sends a response message with the appropriate HTML source so that the error information is displayed in the browser window.
Web Server in Java: Part A
In the following steps, we will go through the code for the first implementation of our Web server. Wherever you see "?," you will need to supply a missing detail.
Our first implementation of the Web server will be multi-threaded, where the processing of each incoming request will take place inside a separate thread of execution. This allows the server to service multiple clients in parallel, or to perform multiple file transfers to a single client in parallel. When we create a new thread of execution, we need to pass to the Thread's constructor an instance of some class that implements the
Runnable
interface. This is the reason why we define a separate class called
HttpRequest
. The structure of the Web server is shown below:
import java.io.* ;
import java.net.* ;
import java.util.* ;
public final class WebServer
{
public static void main(S.
MCIS 6163 Assignment 1/MCIS 6163 Assignment 1.pdf
Assignment 1 – MCIS 6163
Building a Simple Web Client and a Multithreaded Web Server
Objectives
To understand client-server communication via sockets.
To gain exposure to the basic operations of a Web server and client.
To explore basic structures of HTTP messages.
Due: April 14, 2020 11:59pm
Project Description
In this project, you will be developing a multithreaded Web server and a simple web client. The Web
server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer
Protocol).
Requirements for the Web server
The server is able to handle multiple requests concurrently. This means the implementation is
multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an
HTTP request, the server sets up a TCP connection to the requesting client and serves the request in a
separate thread. After sending the response back to the client, it closes the connection.
The server is assumed to work with HTTP GET messages. If the requested file exists, the server
responds with “HTTP/1.1 200 OK” together with the requested page to the client, otherwise it sends a
corresponding error message, e.g., “HTTP/1.1 404 Not Found” or “HTTP/1.1 400 Bad Request”.
If running the server program using command line, the syntax should be:
server_code_name [<port_number>]
where the optional <port_number> is the port on which the server is listening to connections from
clients. If the port number is not entered, the default port 8080 is used.
You can test your Web server implementation on your local machine using a Web browser, e.g.,
Internet Explorer, Firefox, or Chrome. You need to specify the used port number within the URL, for
example,
http://localhost:8080/index.htm
If omitting the port number portion, i.e., 8080, the browser will use the default port 80.
The server should response with a default page when users do not enter a specific page in the URL,
for example,
http://localhost:8080/
It should also work when the request includes a path to the requested file, for example,
http://localhost:8080/path/to/file/example.htm
You should display/log the request and header lines of request messages on the server for the purpose
of debugging.
Requirements for the simple Web client
The client is able to connect to the server via a socket and to request a page on the server.
Upon receipt of the response message from the server, the client extracts and displays/logs the
message status, and then retrieves the page content from the message body.
If running the client program using command line, the syntax should be:
client_code_name <server_IPaddress/name> [<port_number>] [<requested_file_name>]
where the <server_IPaddress/name> is the IP address or name of the Web server, e.g., 127.0.0.1 or
localhost for the server running on the local machine. The optional < ...
MCIS 6163 Assignment 1/MCIS 6163 Assignment 1.pdf
Assignment 1 – MCIS 6163
Building a Simple Web Client and a Multithreaded Web Server
Objectives
To understand client-server communication via sockets.
To gain exposure to the basic operations of a Web server and client.
To explore basic structures of HTTP messages.
Due: April 14, 2020 11:59pm
Project Description
In this project, you will be developing a multithreaded Web server and a simple web client. The Web
server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer
Protocol).
Requirements for the Web server
The server is able to handle multiple requests concurrently. This means the implementation is
multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an
HTTP request, the server sets up a TCP connection to the requesting client and serves the request in a
separate thread. After sending the response back to the client, it closes the connection.
The server is assumed to work with HTTP GET messages. If the requested file exists, the server
responds with “HTTP/1.1 200 OK” together with the requested page to the client, otherwise it sends a
corresponding error message, e.g., “HTTP/1.1 404 Not Found” or “HTTP/1.1 400 Bad Request”.
If running the server program using command line, the syntax should be:
server_code_name [<port_number>]
where the optional <port_number> is the port on which the server is listening to connections from
clients. If the port number is not entered, the default port 8080 is used.
You can test your Web server implementation on your local machine using a Web browser, e.g.,
Internet Explorer, Firefox, or Chrome. You need to specify the used port number within the URL, for
example,
http://localhost:8080/index.htm
If omitting the port number portion, i.e., 8080, the browser will use the default port 80.
The server should response with a default page when users do not enter a specific page in the URL,
for example,
http://localhost:8080/
It should also work when the request includes a path to the requested file, for example,
http://localhost:8080/path/to/file/example.htm
You should display/log the request and header lines of request messages on the server for the purpose
of debugging.
Requirements for the simple Web client
The client is able to connect to the server via a socket and to request a page on the server.
Upon receipt of the response message from the server, the client extracts and displays/logs the
message status, and then retrieves the page content from the message body.
If running the client program using command line, the syntax should be:
client_code_name <server_IPaddress/name> [<port_number>] [<requested_file_name>]
where the <server_IPaddress/name> is the IP address or name of the Web server, e.g., 127.0.0.1 or
localhost for the server running on the local machine. The optional <.
The document discusses PHP form handling and validation. It covers using the GET and POST methods to submit form data, and the PHP superglobals like $_GET and $_POST that contain this submitted data. It then discusses validating form fields, including checking for required fields, validating names, emails, and URLs. It provides code examples for validating field values and displaying error messages. It also covers basics of SQL like using CREATE TABLE, INSERT, SELECT, WHERE clauses, and JOINs.
The document discusses PHP forms and form handling. It explains that the $_GET and $_POST superglobals are used to collect form data submitted via GET or POST methods. It provides an example HTML form that submits to a PHP file and displays the submitted data. The differences between GET and POST are outlined, including when each method should be used. Validation of required fields is demonstrated with PHP code. Other PHP topics like dates, times, and including files are briefly covered.
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 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.
Walks through the basics of the HTTP protocol, URLs, cookies and caching, with tricks and tips that can be used by web developers. From a Geek.class I did on Oct 6, 2011 for Meet the Geeks.
The document discusses HTTP requests and responses. It explains that HTTP is the most popular application protocol used on the internet. An HTTP client sends a request to a server, which returns a response. Requests use URLs to identify resources and consist of a request line and optional headers. Responses also include a status line and headers to provide information to the client. HTML forms allow sending request data to servers using GET or POST requests.
1. Ruby is a general-purpose language; it can't properly be called a web language at all.
Even so, web applications and web tools in general are among the most common uses of
Ruby.
Not only can you write your own SMTP server, FTP daemon, or Web server in Ruby, but
you can also use Ruby for more usual tasks such as CGI programming or as a
replacement for PHP.
Please spend few minutes with CGI Programming Tutorial for more detail on CGI
Programming.
Writing CGI Scripts:
The most basic Ruby CGI script looks like this:
#!/usr/bin/ruby
puts "HTTP/1.0 200 OK"
puts "Content-type: text/htmlnn"
puts "<html><body>This is a test</body></html>"
If you call this script test.cgi and uploaded it to a Unix-based Web hosting provider with
the right permissions, you could use it as a CGI script.
For example, if you have the Web site http://www.example.com/ hosted with a Linux
Web hosting provider and you upload test.cgi to the main directory and give it execute
permissions, then visiting http://www.example.com/test.cgi should return an HTML page
saying This is a test.
Here when test.cgi is requested from a Web browser, the Web server looks for test.cgi on
the Web site, and then executes it using the Ruby interpreter. The Ruby script returns a
basic HTTP header and then returns a basic HTML document.
Using cgi.rb:
Ruby comes with a special library called cgi that enables more sophisticated interactions
than those with the preceding CGI script.
Let's create a basic CGI script that uses cgi:
#!/usr/bin/ruby
require 'cgi'
cgi = CGI.new
2. puts cgi.header
puts "<html><body>This is a test</body></html>"
Here you created a CGI object and used it to print the header line for you.
Form Processing:
Using class CGI gives you access to HTML query parameters in two ways. Suppose we
are given a URL of /cgi-bin/test.cgi?FirstName=Zara&LastName=Ali.
You can access the parameters FirstName and LastName using CGI#[] directly as
follows:
#!/usr/bin/ruby
require 'cgi'
cgi = CGI.new
cgi['FirstName'] # => ["Zara"]
cgi['LastName'] # => ["Ali"]
There is another way to access these form variables. This code will give you a hash of all
the key and values:
#!/usr/bin/ruby
require 'cgi'
cgi = CGI.new
h = cgi.params # => {"FirstName"=>["Zara"],"LastName"=>["Ali"]}
h['FirstName'] # => ["Zara"]
h['LastName'] # => ["Ali"]
Following is the code to retrieve all the keys:
#!/usr/bin/ruby
require 'cgi'
cgi = CGI.new
cgi.keys # => ["FirstName", "LastName"]
If a form contains multiple fields with the same name, the corresponding values will be
returned to the script as an array. The [] accessor returns just the first of these.index the
result of the params method to get them all.
In this example, assume the form has three fields called "name" and we entered three
names "Zara", "Huma" and "Nuha":
3. #!/usr/bin/ruby
require 'cgi'
cgi = CGI.new
cgi['name'] # => "Zara"
cgi.params['name'] # => ["Zara", "Huma", "Nuha"]
cgi.keys # => ["name"]
cgi.params # => {"name"=>["Zara", "Huma", "Nuha"]}
Note: Ruby will take care of GET and POST methods automatically. There is no separate
treament for these two different methods.
An associated, but basic, form that could send the correct data would have HTML code
like so:
<html>
<body>
<form method="POST" action="http://www.example.com/test.cgi">
First Name :<input type="text" name="FirstName" value="" />
<br />
Last Name :<input type="text" name="LastName" value="" />
<input type="submit" value="Submit Data" />
</form>
</body>
</html>
Creating Forms and HTML:
CGI contains a huge number of methods used to create HTML. You will find one method
per tag. In order to enable these methods, you must create a CGI object by calling
CGI.new.
To make tag nesting easier, these methods take their content as code blocks. The code
blocks should return a String, which will be used as the content for the tag. For example:
#!/usr/bin/ruby
require "cgi"
cgi = CGI.new("html4")
cgi.out{
cgi.html{
cgi.head{ "n"+cgi.title{"This Is a Test"} } +
cgi.body{ "n"+
cgi.form{"n"+
cgi.hr +
cgi.h1 { "A Form: " } + "n"+
cgi.textarea("get_text") +"n"+
cgi.br +
cgi.submit
4. }
}
}
}
NOTE: The form method of the CGI class can accept a method parameter, which will set
the HTTP method ( GET, POST, and so on...) to be used on form submittal. The default,
used in this example, is POST.
This will produce following result:
Content-Type: text/html
Content-Length: 302
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<HTML>
<HEAD>
<TITLE>This Is a Test</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">
<HR>
<H1>A Form: </H1>
<TEXTAREA COLS="70" NAME="get_text" ROWS="10"></TEXTAREA>
<BR>
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
Quoting Strings:
When dealing with URLs and HTML code, you must be careful to quote certain
characters. For instance, a slash character ( / ) has special meaning in a URL, so it must
be escaped if it's not part of the pathname.
For example, any / in the query portion of the URL will be translated to the string %2F
and must be translated back to a / for you to use it. Space and ampersand are also special
characters. To handle this, CGI provides the routines CGI.escape and CGI.unescape.
#!/usr/bin/ruby
require 'cgi'
puts CGI.escape(Zara Ali/A Sweet & Sour Girl")
This will produce following result:
Zara+Ali%2FA Sweet+%26+Sour+Girl")
5. Similarly you may want to escape HTML special characters:
#!/usr/bin/ruby
require 'cgi'
puts CGI.escapeHTML('<h1>Zara Ali/A Sweet & Sour Girl</h1>')
This will produce following result:
<h1>Zara Ali/A Sweet & Sour Girl</h1>'
Useful Methods in CGI Class:
Here is complete listing of all the methods related to CGI class:
• The Ruby CGI - Methods related to Standard CGI library.
Cookies and Sessions:
I have explained these two concepts in different links. Please follow these links:
• The Ruby CGI Cookies - How to handle CGI Cookies.
• The Ruby CGI Sessions - How to manage CGI sessions.
Web Hosting Servers:
You could check following links to host yoru website on a Unix-based Server:
• Unix-based Web hosting
Sending Email using Ruby - SMTP
Simple Mail Transfer Protocol (SMTP) is a protocol which handles sending e-mail and
routing e-mail between mail servers.
Ruby provides Net::SMTP class for Simple Mail Transfer Protocol (SMTP) client-side
connection and provides two class methods new and start.
• The new takes two parameters:
o The server name defaulting to localhost
o The port number defaulting to the well-known port 25
• The start method takes these parameters:
6. o The server - IP name of the SMTP server, defaulting to localhost
o The port - Port number, defaulting to 25
o The domain - Domain of the mail sender, defaulting to
ENV["HOSTNAME"]
o The account - Username, default is nil
o The password - User password, defaulting to nil
o The authtype - Authorization type, defaulting to cram_md5
An SMTP object has an instance method called sendmail, which will typically be used to
do the work of mailing a message. It takes three parameters:
• The source - A string or array or anything with an each iterator returning one
string at a time.
• The sender - A string that will appear in the from field of the email.
• The recipients - A string or an array of strings representing the recipients'
addressee(s).
Example:
Here is a simple way to send one email using Ruby script. Try it once:
require 'net/smtp'
message = <<MESSAGE_END
From: Private Person <me@fromdomain.com>
To: A Test User <test@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, 'me@fromdomain.com',
'test@todomain.com'
end
Here you have placed a basic e-mail in message, using a here document, taking care to
format the headers correctly. An e-mails requires a From, To, and Subject header,
separated from the body of the e-mail with a blank line.
To send the mail you use Net::SMTP to connect to the SMTP server on the local machine
and then use the send_message method along with the message, the from address, and the
destination address as parameters (even though the from and to addresses are within the
e-mail itself, these aren't always used to route mail).
If you're not running an SMTP server on your machine, you can use Net::SMTP to
communicate with a remote SMTP server. Unless you're using a webmail service (such
7. as Hotmail or Yahoo! Mail), your e-mail provider will have provided you with outgoing
mail server details that you can supply to Net::SMTP, as follows:
Net::SMTP.start('mail.your-domain.com')
This line of code connects to the SMTP server on port 25 of mail.your-domain.com
without using any username or password. If you need to, though, you can specify port
number and other details. For example:
Net::SMTP.start('mail.your-domain.com',
25,
'localhost',
'username', 'password' :plain)
This example connects to the SMTP server at mail.your-domain.com using a username
and password in plain text format. It identifies the client's hostname as localhost.
Sending an HTML email using Ruby:
When you send a text message using Ruby then all the content will be treated as simple
text. Even if you will include HTML tags in a text message, it will be displayed as simple
text and HTML tags will not be formatted according to HTML syntax. But Ruby
Net::SMTP provides option to send an HTML message as actual HTML message.
While sending an email message you can specify a Mime version, content type and
character set to send an HTML email.
Example:
Following is the example to send HTML content as an email. Try it once:
require 'net/smtp'
message = <<MESSAGE_END
From: Private Person <me@fromdomain.com>
To: A Test User <test@todomain.com>
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test
This is an e-mail message to be sent in HTML format
<b>This is HTML message.</b>
<h1>This is headline.</h1>
MESSAGE_END
Net::SMTP.start('localhost') do |smtp|
8. smtp.send_message message, 'me@fromdomain.com',
'test@todomain.com'
end
Sending Attachements as an e-mail:
To send an email with mixed content requires to set Content-type header to
multipart/mixed. Then text and attachment sections can be specified within boundaries.
A boundary is started with two hyphens followed by a unique number which can not
appear in the message part of the email. A final boundary denoting the email's final
section must also end with two hyphens.
Attached files should be encoded with the pack("m") function to have base64 encoding
before transmission.
Example:
Following is the example which will send a file /tmp/test.txt as an attachment. Try it
once:
require 'net/smtp'
filename = "/tmp/test.txt"
# Read a file and encode it into base64 format
filecontent = File.read(filename)
encodedcontent = [filecontent].pack("m") # base64
marker = "AUNIQUEMARKER"
body =<<EOF
This is a test email to send an attachement.
EOF
# Define the main headers.
part1 =<<EOF
From: Private Person <me@fromdomain.net>
To: A Test User <test@todmain.com>
Subject: Sending Attachement
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=#{marker}
--#{marker}
EOF
# Define the message action
part2 =<<EOF
Content-Type: text/plain
Content-Transfer-Encoding:8bit
9. #{body}
--#{marker}
EOF
# Define the attachment section
part3 =<<EOF
Content-Type: multipart/mixed; name="#{filename}"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename="#{filename}"
#{encodedcontent}
--#{marker}--
EOF
mailtext = part1 + part2 + part3
# Let's put our code in safe area
begin
Net::SMTP.start('localhost') do |smtp|
smtp.sendmail(mailtext, 'me@fromdomain.net',
['test@todmain.com'])
end
rescue Exception => e
print "Exception occured: " + e
end
NOTE: You can specify multiple destinations inside the array but they should be
separated by comma.