Win a copy of Head First Android this week in the Android forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Socket beginner

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a few problems using sockets and connecting to a server.

I've got a server.jar file that runs on my machine and I have a client interface that needs to connect to the server and send and recieve messages using output/input streams.

Firstly, the socket constructor is Socket(remoteHost, port). I've got the port number, but as the server is running on my own machine should I use my hostname/ip address as the remoteHost as this is what I'm currently doing? This method does connect to the server (which is confirmed in the terminal window running the server), which in turn creates a GUI.

Once connected, I'm able to send messages to the server using a BufferedWriter. There is a logout command which is called by a button on the GUI. To logout, a message is sent to the server and log's the user off correctly. However, I also need to close the socket. This is the code I'm using >

try {
} catch (Exception e) {

When this code is inserted and the logout button is clicked the system freezes and doesn't logout, despite this code appearing after the logout command has been sent to the server. Is there any obvious reason why this would happen?
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure the system freezes or have you not written anything to display that the connection is gone.
just wondering
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic