Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple Chat application using sockets, readers and writers.i need some help

843789Nov 30 2009 — edited Nov 30 2009
Hello Guys,

I am creating a simple chat application that will run from a serverSocket to a socket on a client host.

ok i have got it to work. there is a textfield, send and exit button.

what i would like to do it to be able to add a checkbox that will allow for character by character sending over the sockets. instead of line by line and then press the send button.

so what i started to do is for my the client and server application to implement KeyListener

so when a key is typed it will do this
	public void keyTyped(KeyEvent arg0) {
		try {
			System.out.print(arg0.getKeyChar());//just for testing if keyTyped works
			bw.write(arg0.getKeyChar());//bw being my buffered writer
			bw.newLine();
/* i had to call this method and the one below so that the character could be displayed on the other application. my problem is that the characters are going to a new line everytime a key is pressed. if i take out the newLine() method then it does not display the character*/
			bw.flush();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}
i am a bit stuck for the moment . if some one could help that would be great/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 28 2009
Added on Nov 30 2009
1 comment
191 views