Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/211279-java-im-program-networking-issue/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.