I Want To Make Programme Such That
I Make The Programme In Two Sockets One For Client Other For Server,

A Server Establish A Connection With The Client, Then Client Has To Enter Username Either John Or Jammi Then The Password For The Username Any Of The Above,

Please Tell Me How To Do This Coding

i need programme coding i know how to run
but i dont understand how to do coding for this programme

What exactly do you not understand?

We are not here to do your (home)work for you. That is expressly forbidden by the terms and conditions you agreed to when you opened a membership here.

sorry to bother you

i didn't mean that you do my home work

i have made a programme.

but i have to put that in two sockets...
and i have made the sockets for client and servers too, but there is some mistake in the coding ,,, thats all..
i am extremely sorry to disturb you

I will do that myself
thank you for your reply
Regards
Crab

Post your code, and the complete error messages and we will help you to correct them (and use code tags).

[code]
// your code here
[/code]
looks like this

// your code here

here is the code for server..

/**
 * Created by IntelliJ IDEA.
 * User: john
 * Date: 1-Feb-2008
 * Time: 20:53:08
 * To change this template use File | Settings | File Templates.
 */

import java.net.ServerSocket;
import java.net.Socket;
import java.io.*;
import java.util.Date;

class Server
{
  // Choose a port outside of the range 1-1024:
  public static final int PORT = 5432;
  public static final String
        startTag = "SENDING FILE",
        endTag = "END OF FILE";
  public static void main(String[] args)
      throws IOException {
    ServerSocket s = new ServerSocket(PORT);
    System.out.println("Server: beginning " + s);
    // Ready for clients now:
    try {
          // Blocks until a connection occurs:
          Socket client = s.accept();
         try {
              BufferedReader in =new BufferedReader(new InputStreamReader(client.getInputStream()));
              PrintWriter out =new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true);
               while(true)
                 {
                  String str=in.readLine();
                  System.out.println(str);
                  System.out.println("Server: connection accepted");
                  out.flush();
                  if(str.equals("end"))
                  break;
                 }
              System.out.println("Please Log on,type in Logon at frist, then type in your name and password");
              JavaCaesar unencrpy=new JavaCaesar();
               boolean flag=false;
              String name,password;
              String username[],pwd[];
              username[200]=in.readline();
              for(int i=0;i<username[200].length;i++){
                  name=(String)unencrpy.caesar(username[200]);
                  }
              pwd[200]=in.readline();
              for(int j=0;j<pwd[200].length;j++){
                  password=(String)unencrpy.caesar(pwd[200]);
                  }
                  if((name.equals("Anne")&&(password.equals("fish"))||(name.equals("Bill")&&password.equals("fowl"))))
                  {
                      flag=true;
                      }

              System.out.println("1: ask for the date. 2: transfer a file. 3: log out");
              BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
              while(flag)
              {
                   switch(in1.read())
                   {
                      case 1:
                          {
                              Date date = new Date();
                              System.out.println("The Date is:" + date);
                              break;
                          }
                      case 2:
                          {
                              out.println(startTag);
                              BufferedReader file = null;
                              try
                               {
                                file = new BufferedReader(new FileReader("transfer.txt"));
                                String fs = null;
                                while ((fs = file.readLine()) != null)
                                out.println(fs);
                                out.println(endTag);
                               }
                             catch (IOException e)
                             {
                              if (file != null)
                              file.close();
                              System.out.println("Error: " + e);
                              System.exit(1);
                             }
                             break;
                         }
                     case 3:
                        {
                            System.out.println("closing...");
                            client.close();
                            break;
                        }
                   }
              }
         }
         catch(Exception e1)
         {
          System.out.println(e1.getMessage());
         }
    }
    finally
    {
        s.close();
    }
  }
}

here is code for CLient scoket

/**
 * Created by IntelliJ IDEA.
 * User: john
 * Date: 7-Feb-2008
 * Time: 16:19:56
 * To change this template use File | Settings | File Templates.
 */

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.InetAddress;


public class Client{
 static Socket server;
      public void logon(String name,String password)throws Exception{
           JavaCaesar encrpy=new JavaCaesar();
           System.out.println("Please enter the name:");
           BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
            name=buf.readLine();
            byte[] buf3=new byte[200];
            int count=name.length();
            for(int j=0;j<count;j++)
            buf3[j]=encrpy.caesar(buf3[j],2);
            System.out.println("Please enter the password:");
            BufferedReader buf1=new BufferedReader(new InputStreamReader(System.in));
            password=buf1.readLine();
            byte[] buf2=new byte[200];
            count=password.length();
           for(int i=0;i<count;i++)
           {
               buf2[i]=encrpy.caesar(buf2[i],2);
           }
      }
 public static void
 main(String[] args)
 throws Exception
 {
  server=new Socket(InetAddress.getLocalHost(),5432);
  BufferedReader in=new BufferedReader(new InputStreamReader(server.getInputStream()));
  PrintWriter out=new PrintWriter(server.getOutputStream());
  BufferedReader wt=new BufferedReader(new InputStreamReader(System.in));
  while(true)
   {
     String str=wt.readLine();
     out.println(str);
     out.flush();
     if(str.equals("end"))
     {
      break;
     }
     if (in.readLine().equals("Logon"))
     {

     }
  }
 }
  server.close();
 }
}

I am still unable to run both the sockets
I dont understand the error

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.