0

I'm trying to make a client chat application using Java I want to transfer messages but Its seems like its not working. Typing is a JTextField

Button is a button (No way :O)

and ChatView is the JTextAreafor sending messages between the clients Leave the length() its there so the button doesn't accept spam.

Heres code

 public  void actionPerformed(ActionEvent e){
     int x = Typing.getText().length();
      if (x > 0)  {
     System.out.println(Typing.getText().length());
     ChatView.insert("\n"+Typing.getText(),0);
     Typing.setText("");}
       try {
    ServerSocket MainServer = new ServerSocket(344);
Socket Connect = MainServer.accept();  
OutputStream outstream =  Connect.getOutputStream(); 
 PrintWriter out = new PrintWriter(Connect.getOutputStream());
 out.print("Works");   
} catch (Exception ee) {
    System.err.print("/n"+"error");
}
Samuel Musa
  • 68
  • 2
  • 11
  • Show your client side code as well... the reading part from socket. May be the problem is in client code – AJ. Apr 03 '15 at 15:17
  • Wait what ? We have to read from a socket ? – Samuel Musa Apr 03 '15 at 15:19
  • The code you showed is just the server side code .. show the client side code which is accepting `"Works"` – AJ. Apr 03 '15 at 15:20
  • Ok Well i'm new to sockets like three days. What my idea was to send message to server socket then add a listener to update the jtextarea. So i don't have a client side – Samuel Musa Apr 03 '15 at 15:23
  • Hahaha.. Dude .. First try a simple Socket program .. then jump to big things.. simply hit google Socket programming – AJ. Apr 03 '15 at 15:25
  • AJ i fixed it apparently i mistakenly pasted two tries on my notepad – Samuel Musa Apr 03 '15 at 15:50

1 Answers1

0

The problem is , stream should be flushed if some body is trying to read that stream

After out.print("Works"); either flush the the stream or close the srtream

out.flush(); or out.close();

AJ.
  • 4,526
  • 5
  • 29
  • 41