• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

client/server/etc. question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first time posting, so hopefully I'm putting this in the right area; I trust someone will move it if not. Okay, here goes:
I have a simple chat room app that will eventually be worked into a servlet with SQL Server features. Trouble is, I can't do the fancy stuff until I clean up a bug. It seems to be connecting to host/port just fine (I even pinged myself to make sure my machine would receive), the GUI comes up, I can enter a message and hit "Send" and the JTextField clears- but the message doesn't post in the frame below, it just disappears. No exceptions are being thrown, and nothing in the console indicates why I don't see my postings. I've tried my specific port as well as 127.0.0.1:8080, seeing if I needed to use a different GUI object to attach the input to in order to make it visible, all sorts of stuff. This is an old example from a Java course I took which I'd like to adapt (thought it would "save me time"- yeah, right), but I can't figure out why it worked in class and not now.
The code is a bit long to post, so I'll defer to y'all to tell me whether or not to put some up. Thanks in advance for any help you can give me.
 
Chris Wagner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello? Anybody home?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... we need to narrow down where the error is occurring. I'd suggest putting in System.out.println() statements in various places within the code that you expect to be activiated in the course of processing your message. That way you get some reports on the progress of your message through the system - at some point, there will be a message you expect to see that isn't printed out, and that will tell you that the problem is somewhere between the last printed message and the first message that wasn't printed. If that's still a big section of code, then go back and insert more print statements in that region to help narrow it down further. Often, it's also useful for these messages to also print out current values of variables which show just what a given piece of code is doing. In particular, printing out the text of the message which you're working with is probably useful - you may well find that a section of code is being run, but the message is blank. Again, this tells you the problem is somewhere before that print statement.
If this doesn't help, you may indeed want to post your code. (Be sure to format it as well as possible and use the [ code] and [ /code] tags (read about them here) to preserve that formatting. Good luck.
 
Chris Wagner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim- I think I may have identified the problem, but I don't know how to correct it. I have a Client and a Server class, and Client (which makes the connection request) is throwing "java.net.ConnectException: Connection refused: no further information". This is coming from the following "try" block:

Hope the formatting turns out (my first time posting code); anything stand out? In case you're wondering about the port number, I've tried 8000, 8080, 9090, etc. just out of frustration (hence 9090 above). Thanks for the help.
[This message has been edited by Chris Wagner (edited April 17, 2000).]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing jumps out to me, but then I haven't connected to that many ports, so I don't know all the thinks that might go wrong. Hopefully someone else has an idea?
As an aside, your catch block can use e.printStackTrace() to print out basically the same info, and more. And later on if you add lines and line 65 is no longer line 65, you'll still get the right number printed.
 
Chris Wagner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what I'm wondering: could this be due to a configuration problem of any sort (classpath, JDK, non-Java related, etc.)? This isn't an applet or servlet- just a regular ol' Java application. Each class has at least 100 lines of code, so I don't want to post any of it unless people think there's no way to solve this without a quick peek. As a final note: this is happening at runtime (code compiles just fine).
[This message has been edited by Chris Wagner (edited April 18, 2000).]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt it's anything to do with classpath or the jdk, but could well have to do with the configuratoin of some other part of your machine - e.g. its networking setup. Don't know much about that, myself.
Let's be sure which line is throwing the exception. It's probably the new Socket(), but it could conceiveably be the new ClientGetMessages(), since I have no idea what other code is in there. Put in a e.printStacktrace() to be sure exactly which line is throwing the exception. Then, if it's the new Socket() as I suspect, you really don't care about the rest of the program for now. Try a simple test program:
<code><pre>import java.net.*;

public class Test {
public static void main(String[] s) {
try {
Socket socket = new Socket("127.0.0.1", 9090);
System.out.println("Success!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}</pre></code>
Assuming this doesn't connect either, you can focus on this code by itself. Play around with the numbers, or go to the Sockets and Internet Protocols forum here at JavaRanch and ask there (since we don't appear to be attracting the attention of anyone knowledgeable about sockets here so far.)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic