Go Back   Java Programming Forums > Java Standard Edition Programming Help > Java Networking


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 15-12-2009, 05:52 PM
Junior Member
 

Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
subhopam is on a distinguished road
Default client server program on a single machine

i hv done a program on a server client program on my own machine...i m posting the code..what i want to do is what i type in client site will be seen on the server site too..pls help me...

Client...

Java Code
import java.io.*;
import java.net.*;

public class Client {

	public static void main(String args[]) throws Exception	{
	 	Socket cs = new Socket("localhost",6666);
		int flag=1;
	 	DataInputStream dis = new DataInputStream(System.in);
		System.out.println("Client:");
		ObjectOutputStream oos=new ObjectOutputStream(cs.getOutputStream());
		while(flag==1)
               {
	 	//String str = dis.readLine();
	 	//System.out.println(str);
	 	oos.writeObject(dis.readLine());
	 	if((str=="bye")||(str=="BYE"))
			flag=0;
		}
		oos.close();
		dis.close();
	 cs.close();
	}
}

Server...

Java Code
import java.io.*;
import java.net.*;

 
class Server
	{
	public static void main(String args[]) throws Exception
         {
		ServerSocket ss=new ServerSocket(6666);
		Socket ss1=ss.accept();
		boolean flag=true;
		DataInputStream dis=new DataInputStream(ss1.getInputStream());
		System.out.println("connection established......");
		System.out.println("server:");
		ObjectOutputStream ps=new ObjectOutputStream(ss1.getOutputStream());
		while(flag==true){
			
			String str=dis.readLine();
			System.out.println(str);
			if((str=="bye")||(str=="BYE"))
				flag=false;
				}
		System.out.println("connection closed....");
		ps.close();
		ss1.close();
		ss.close();
			
			}
		}
i m unable to produce the desired result..




Last edited by Freaky Chris; 16-12-2009 at 09:51 AM.
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 16-12-2009, 06:02 PM
Junior Member
 

Join Date: May 2009
Posts: 24
Thanks: 1
Thanked 1 Time in 1 Post
Koâk is on a distinguished road
Default Re: client server program on a single machine

I think the easiest way to get data from point A to point B trough socket is using DataInputStream and DataOutputStream

DataInputStream (Java 2 Platform SE v1.4.2)
DataOutputStream (Java 2 Platform SE v1.4.2)

Last edited by Koâk; 16-12-2009 at 06:05 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exceptions with my simple Client and server programs Dko Exceptions 0 13-12-2009 02:09 AM
Simple server-client trouble DC200 Java Networking 3 12-11-2009 12:16 PM
how compose in the top of the same machine since is a client is also serve NARs Java Applets 2 23-10-2009 07:34 AM
Download a file to client from server mvittalreddy Java Networking 4 05-10-2009 09:23 AM
instead of printing in the client, report get printed in the server jmvenkat Java Theory & Questions 0 19-09-2009 06:30 AM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 02:04 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.