*/
If you have a PH account, you can customize your PH profile.
*/

View java\java\bin\manoveg\client\SecondConn.java

networking authentication program 1.0

Submitted By: manoveg
Rating: (Not rated) (Rate It)


package client;
//import server.*;
import java.net.*;
import java.io.*;
import javax.swing.*;


public class SecondConn {
public static void receive(String username,String password,String npassword)
 {

  String sendstring="#"+username+"$"+password+"$"+npassword;
// make sure you give the port number on which the server is listening.
int serverPort = 8189;
// this is the IP address of the server program's computer.
// the address given here means "the same computer as the client".
String address = "127.0.0.1";
 
try
{
// create an object that represents the above IP address.
InetAddress ipAddress = InetAddress.getByName(address);
System.out.println("Any of you heard of a socket with IP address " + address + " and port " + serverPort + "?");
// create a socket with the server's IP address and server's port.
 Socket socket = new Socket(ipAddress, serverPort);
System.out.println("Yes! I just got hold of the program.");
 // Get the input and output streams of the socket, so that you can receive and send data to the client.
InputStream sin = socket.getInputStream();
OutputStream sout = socket.getOutputStream();
 // Just converting them to different streams, so that string handling becomes easier.
DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
 // Create a stream to read from the keyboard.
//BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
 String line = null;
//System.out.println("Type in something and press enter.");
System.out.println();
// while(true) {
// wait for the user to type in something and press enter.
//line = keyboard.readLine();
 System.out.println("Sending this line to the server...");
// send the above line to the server.


out.writeUTF(sendstring);
// flush the stream to ensure that the data reaches the other end.
out.flush();
// wait for the server to send a line of text.
line = in.readUTF();


if(line.equalsIgnoreCase("Pwd successful"))
{
 Confirmdialog cd = new Confirmdialog(new CFrontEndp(),"Status",line);
 cd.setVisible(true);
}
else
{
 if(line.equalsIgnoreCase("Pwd Failed"))
{
 Confirmdialog cd1 = new Confirmdialog(new CFrontEndp(),"Status",line);
 cd1.setVisible(true);
}
}

 System.out.println("The server was very polite. It sent me this : " + line);



//}


} catch(Exception x)
 {
  x.printStackTrace();
 }
}
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.