0% found this document useful (0 votes)
6 views7 pages

Java Expt 10

Java Expt 10

Uploaded by

arlabpsgptc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Java Expt 10

Java Expt 10

Uploaded by

arlabpsgptc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
Tmploment client and server using datagram socket/stream socket AIM: To implement client and server using datagram socket/stream socket. SOFTWARE REQUIRED: NAME OF THE DEVICE | QUANTITY Working pe 1 2. Java JDK 1 ALGORITHM: Server Side: * Create a DatagramSocket instance to listen for incoming datagrams on a specific port. {Create a byte array to hold the incoming data, {Create a DatagramPacket to receive the incoming data into the byte array, * Use the DatagramSocket’s receive method to receive the datagrem packet. * Process the received data + Optionally, create a DatagramPacket to send a response tothe client. * Use the DatagramSocket's send method to send the Tesponse datagram packet. * Close the DatagramSocket when done. Client Side: 3 Create a DatagramSocket instance for sending datagrams. * Create a byte array to hold the data to be sent, * Create a DatagramPacket with the data and destination address/port, $ Use the DatagramSocket's send method to send the datagratn packet. { Optionally, create a DatagramPacket to receive a response from the server + Use the DatagramSocket's receive method to receive the response datagram packet, * Process the received response. * Close the DatagramSocket when done. PROGRAM: DatagramSocketClient java: import java.net. DatagramPacket; import java.net, DatagramSocket; import java net.InctAddress; public class DatagramSocketClient { public static void main(String[] args) { try { String message = "Hello, server!"; byte(] buffer = Message getBytes(); DatagramPacket packet = new DatagramPacket(buffer, ‘ServerPort); socket.send(packet);, System.out.printin(""Message sent to server: " + message); socket.close(); } catch (Exception e) { e printStackTrace(); } } DatagramSocketServer java: import, Java.net,DatagramPacket; import java.net DatagramSocket; Public class DatagramSocketServer a Public static void main(String(] args) { try { DatagramSocket socket = new DatagramSocket(1234); byte(] buffer = new byte{ 1024; } catch (Exception e) { eprintStackTrace(); RESULT: Thus we have Successfully implement the client and server socket. : AIM: : To Implement JDBC Connectivity PROCEDURE: STEP 1: SETUP THE DIRECTORIES 1, Create a file named exp10 in C > xampp > tomeat > webapps v directory. 2. Create 2 sub directories namely sre and WEB-INF inside the where the program files will also be stored. 3. Inside your sre subdirectory you have to save the java file named. . 4. Inside your WEB-INF subdirectory you have to create 2 more namely classes and lib, also save the xml file named web.xml. 5. Inside your lib sub subdirectory you have to save two mysql-connector-j-8.0.32,jar and servlet-api-7.0.6,jar. STEP 2: CREATE THE REQUIRED FILES 1. For this particular experiment we will be in need of 2 html files and 2. The three html files are namely home.html and register.html. 3. The jsp files are namely register. jsp. 4. Place all these four files inside the main directory exp10. STEP 3: EXECUTE THE FILES 1. Open a browser to local host the file named register.html, 2, Type the following for hosting the webpage hittp://localhost:8080/exp 10/register.html, PROGRAM: home.htmt shiml> Home | PSG Polytechnic Collegehitle> ee ;

MySQL JDBC Connectivity Established!-

as

Please check the MySQL database to verify that the Successfully stored and confirm the connectivity using JDBC

SQL Query CREATE DATABASE mydb; USE mydb; CREATE TABLE ‘users’ ( id INT, sername VARCHAR(30), password VARCHAR(30), fullname VARCHAR(50), email VARCHAR(50) i | | | register.html Registration

Fill the Below details



-

a < 'Signup">
register,jsp <%@ page import="java.sql.*" %> % String username = request getParameter("username");, String password = request.getParameter("password"); String fullname = request getParameter("fullname"); String email = request getParameter("email"); try { // Connect to the database Class.forName("com.mysql,jdbe-Driver"); Connection con = DriverManager.getConnection("jdbe:mysql:/localhost:3306/m trieval=true", "root", "); ‘lnsest user details ito the database PreparedStatement stmt = con.prepareStatement("INSERT | // Redirect to the login page response.sendRedirect(“home.htm!"); } catch(Exception e) { outprintia(e); } % RESULT: Thus we have successfully written and executed | of the 3 or 4 users who register with the webpage by using authenticate theuser if he submits the login form using th the database,

You might also like