Want to see what people are talking about? See the latest forum posts.

View java\java\bin\manoveg\server\Server1.java

networking authentication program 1.0

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


package server;
import client.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.event.*;

public class Server1
{
 public static void main(String[] ar)
 {
 int port = 8189; // just a random port. make sure you enter something between 1025 and 65535.
 try {
    ServerSocket ss = new ServerSocket(port); // create a server socket and bind it to the above port number.
while(true)
{
    System.out.println("Waiting for a client...");
 Socket socket = ss.accept(); // make the server listen for a connection, and let you know when it gets one.
 System.out.println("Got a client :) ... Finally, someone saw me through all the cover!");
    System.out.println();
 // 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);
 String line = null;
 String conf="";
 

 
 // wait for the client to send a line of text.
 line = in.readUTF();
 System.out.println("The dumb client just sent me this line : " + line);
 CheckClient c1 = new CheckClient();
char ch=line.charAt(0);
if(ch!='#')
 conf=c1.check(line);
else

  conf=c1.checkPwd(line);


 
System.out.println("conf  :"+conf);
 out.writeUTF(conf);
 // flush the stream to ensure that the data reaches the other end. 
out.flush();
 System.out.println("Waiting for the next line...");
    System.out.println();
}


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

corner
© 1996-2008. 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.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.