1 Replies - 658 Views - Last Post: 27 July 2007 - 08:20 AM Rate Topic: -----

#1 scarecrowfeild  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 14-July 07

program can run but...

Posted 27 July 2007 - 08:17 AM

hi!
i had write 2 programs.1 for each client and server.
i already compile and run both of them.
But Server didn't send the answer to Client after it compute the numbers.

[color=#3333FF]this is the Client side


	try{	
	 Socket connection=new Socket("localhost",port);
	while(true){

			DataInputStream in=new DataInputStream(connection.getInputStream());
			DataOutputStream out=new DataOutputStream(connection.getOutputStream());
		InputStreamReader isr=new InputStreamReader(System.in);
		BufferedReader br=new BufferedReader(isr);
		String stnum=JOptionPane.showInputDialog("Enter integer less than 10 digits");
		out.writeBytes(stnum);
			System.out.println(in.readInt());
			}	
			}//end try


this is the Server side
try
		{ServerSocket serverSocket=new ServerSocket(Port);//create server socket
		Socket connection=serverSocket.accept();//listening for connection request
	 	//create input&output stream
		DataInputStream receive=new DataInputStream(connection.getInputStream());
		DataOutputStream send=new DataOutputStream(connection.getOutputStream());
		System.out.println("connection started");
		do{
			number=receive.readInt();
		for(int temp=number;temp>=0;temp=temp/10){
		int b=number%10;
			total= total+b;
			number=number/10;}//end for
		send.writeInt(total);
			}//end do
		while(total>9);
		}//end try


edit: added code tags ~ jayman9

Is This A Good Question/Topic? 0
  • +

Replies To: program can run but...

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: program can run but...

Posted 27 July 2007 - 08:20 AM

Hi scarecrowfeild can you put the code next time between code tags and not in colour like this, it's hard to read it this way thx.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1