proggR Posted August 20, 2010 Share Posted August 20, 2010 Hey. I was going to make a browser based IM program with a Java backend but I've thought of a few ways to make it better and using a thick client will help make them easier. I have the backend done and was able to reuse all the code I already made by adding a ClientController class that interfaces between the client and all the other code. My problem now is connecting the client to the ClientController. I'm trying to use Sockets to transfer the information. The server side ClientController seems to be working and replies to any connections and receives any information send. But on the client side it can receive information once and then no more. Further more if I put the code for receiving information in a loop it prevents the JFrame that would normally allow for input from rendering at all. In the console it still receives the "Connection Established" message from the server but it gets stuck. The code I'm using on the client side is the following. The server side is similar except it also uses a ServerSocket. I'm wondering if I need to add a ServerSocket to the client but I don't know how that would be implemented. requestSocket = new Socket("localhost", 4501); System.out.println("Connected to localhost in port 4501"); out = new ObjectOutputStream(requestSocket.getOutputStream()); out.flush(); in = new ObjectInputStream(requestSocket.getInputStream()); message = (String) in.readObject(); if (message != null) { System.out.println("server>" + message); serverData.add(message); } refreshList(); in.close(); Note this isn't in a loop and will work as long as its not in a loop and has in.close(). I'm wondering if I need some sort of in.wait() but I don't know how I would use that. Also refreshList() is just a function that parses the data from the List<String> called serverData into an array and updates the JList used to display the data onscreen with the result. I've done Java browser apps before but never have I tried connecting a Java thick client to any web-based service so this is new to me. Any help would be appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/211279-java-im-program-networking-issue/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.