Results 1 to 3 of 3
  1. #1
    Elite Member
    Join Date
    May 2011
    Gender
    Male
    Posts
    1,465

    Default Chat java. Naloko na c client.


    mga boss. i'm practicing socket programming in java. chat ni cya
    the problem is, di maka.connect ang client if unahon ug run ang server para mu.create ug socket.
    mu.connect ra ang client if naka.run na cya daan, then paabot cya mu.run ang server para mucreate ug ServerSocket, dha pa cya mu.connect. LAINA UI! hahaha. bali man nuon. dapat mag.una ang server then musunod ug connect ang client.
    here is the code of the client connection.
    kung kbw mo, post mo mga bossing. then add ug mga comments. tnx
    Code:
     try {
                
                boolean connected = false;
                do {
                    try {
                        connection = new Socket( "127.0.0.1", 1234 );
                        connected = true;
                        
                        input_field.setEditable( true );
                        textArea.append( String.format( "Now connected to %s.\n", 
                        connection.getInetAddress() ) ); 
                    } catch ( Exception e ) {
                        connected = false;
                    }
                } while( !connected );
                
                
                        
                
                //read inputs
                Scanner in = new Scanner( new InputStreamReader( connection.getInputStream() ) );
                String line;
                while ( ( line = in.nextLine() ) != null ) {
                    textArea.append( line + "\n" );
                }
                
            } catch ( IOException e ) {
                textArea.append( String.format( "%s\n", e.getMessage() ) );
            }

  2. #2
    in my opinion mo work ra ni siya although naay mga flaws. I think the reason why dili siya maka connect sa imo server if mag una siya ug dagan is because maybe wla natarong ug close imo mga connections. Try to post your server code as well. Based ani na code lang I think naay nag exception but since imo ra gi mark as false imo connected variable nag infinite loop ka sa imo try catch block.

    Here are my advice:

    1. Try to display what went wrong. Put a stackTrace on your catch statement para maka balo ka unsay nahitabo ngano wla ka naka connect.
    2. ALWAYS close your connections by using finally {} block. What ever happens sa imo code, make sure all connections are closed if wla na nimo gigamit.

  3. #3
    Elite Member
    Join Date
    May 2011
    Gender
    Male
    Posts
    1,465
    Quote Originally Posted by dekarcane View Post
    in my opinion mo work ra ni siya although naay mga flaws. I think the reason why dili siya maka connect sa imo server if mag una siya ug dagan is because maybe wla natarong ug close imo mga connections. Try to post your server code as well. Based ani na code lang I think naay nag exception but since imo ra gi mark as false imo connected variable nag infinite loop ka sa imo try catch block.

    Here are my advice:

    1. Try to display what went wrong. Put a stackTrace on your catch statement para maka balo ka unsay nahitabo ngano wla ka naka connect.
    2. ALWAYS close your connections by using finally {} block. What ever happens sa imo code, make sure all connections are closed if wla na nimo gigamit.
    i solved it na. nara koi g.tang2x. there is nothing wrong with the server. the problem was this.
    Code:
     
     try {
                
                boolean connected = false;
                do {
                    try {
                        connection = new Socket( "127.0.0.1", 1234 );
                        connected = true;
                        
                        input_field.setEditable( true );
                        textArea.append( String.format( "Now connected to %s.\n", 
                        connection.getInetAddress() ) ); 
                    } catch ( Exception e ) {
                        connected = false;
                    }
                } while( !connected );
    maglabay cya ug NullPointerException. cguro wa pa niya nakita na.himo ang UI ana na part since ang pag.build sa ui ako man gbutang ug invokeLater na thread, so mag.una jud cya ug connect before mahimo ang UI. yeah dakpon unta cya sa exception but infinite cya
    dakpon sa exception so not connected ghapun.
    Last edited by jairoh_; 05-08-2013 at 06:30 AM.

  4.    Advertisement

Similar Threads

 
  1. client to client chat in java.
    By jairoh_ in forum Programming
    Replies: 14
    Last Post: 05-21-2013, 11:15 AM
  2. chat server w/ multiple clients. java
    By jairoh_ in forum Programming
    Replies: 9
    Last Post: 04-26-2013, 07:17 PM
  3. Chat box?naa na dw soon sa istorya?
    By tiwashi in forum General Discussions
    Replies: 13
    Last Post: 03-02-2012, 01:44 PM
  4. Looking For: Samsung Chat o Nokia na Qwerty!!!
    By jaylordgoring87 in forum Cellphones & Accessories
    Replies: 3
    Last Post: 09-30-2011, 11:00 AM
  5. MOVED: Wanted! Technician na concerned sa client
    By BeoR in forum Software & Games (Old)
    Replies: 0
    Last Post: 08-27-2005, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top