Socket will not send or receive the message (sending to 127.0.0.1)

I don't know if it's my client or my server that's going wrong. I'll put the code here...can any one please tell me what I'm doing wrong? =(
CLIENT
public class ClientSession {
    private ChatWindow parentWindow;
    private BufferedReader in;
    private PrintWriter out;
    public ClientSession(ChatWindow parentWindow, String ip, int port) {
        this.parentWindow = parentWindow;
        try {
            Socket client = new Socket(ip, port);
            parentWindow.say("Connection succesfully established", true);
            System.out.println("Now connected to " + ip + ":" + Integer.toString(port));
            out = new PrintWriter(client.getOutputStream());
            in = new BufferedReader(new InputStreamReader(client.getInputStream()));
        catch(Exception e) {
            System.out.println("Error while connecting: " + e.getMessage());
            parentWindow.say("Failed to connect. Type /connect to retry.", true);
    public void sendMessage(String message) {
        System.out.println("Sending message: " + message);
        out.println(message);         
    }SERVER
public class Server implements Runnable {
    private int port;
    private HashMap<String, ChatWindow> chatWindowList;
    private String name;
    public Server(int port, HashMap<String, ChatWindow> chatWindowList) {
        this.port = port;
        this.chatWindowList = chatWindowList;
        this.name = "";
    public void run() {
        try {
            ServerSocket server = new ServerSocket(port);
            while(true) {
                Socket connection = server.accept();
                String ip = connection.getInetAddress().getHostAddress();
                ChatWindow chatWindow;
                if(chatWindowList.get(ip) == null) {
                    chatWindow = new ChatWindow(ip, port);
                    chatWindowList.put(ip, chatWindow);
                    chatWindow.connect();
                else {
                    chatWindow = chatWindowList.get(ip);
                    chatWindow.activate();
                    chatWindow.connect();
                ServerSession serverSession = new ServerSession(connection, chatWindow, name);
                Thread t = new Thread(serverSession);
                t.start();
        catch(Exception e) {
            System.out.println("Error at the server: " + e.getMessage() + e.toString());
    public void setName(String name) {
        this.name = name;
}SERVERSESSION
public class ServerSession implements Runnable{
    private String name;
    private ChatWindow chatWindow;
    private PrintWriter out;
    private BufferedReader in;
    public ServerSession(Socket connection, ChatWindow chatWindow, String name) {
        this.chatWindow = chatWindow;
        this.name = name;
        if(this.name.equals("") || this.name.equals("Please set name")) this.name = "No name set";
        try {
            out = new PrintWriter(connection.getOutputStream());
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        catch(Exception e) {
            System.out.println("Error while writing to client:" + e.getMessage());
    public void run() {
        System.out.println("Session with Client accepted");
        loopTextAcceptance();
    public void setName(String name) {
        this.name = name;
    private void loopTextAcceptance() {
        try {
            chatWindow.say("reading...", true);
            while(true) {
                chatWindow.say("...", true);
                System.out.println("reading");
                String line = in.readLine();
                System.out.println("line read");
                chatWindow.say(line, false);
        catch(Exception e) {
            System.out.println("Error while recieving message: " + e.getMessage());
}thanks for reading!

the new code resulted from removing the ChatWindow stuff and any other places the errors can't be, is this better?
Server
public class ServerSession implements Runnable{
    private PrintWriter out;
    private BufferedReader in;
    public ServerSession(Socket connection) {
        try {
            out = new PrintWriter(connection.getOutputStream());
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        catch(Exception e) {
            System.out.println("Error while writing to client:" + e.getMessage());
    public void run() {
        System.out.println("Session with Client accepted");
        loopTextAcceptance();
    private void loopTextAcceptance() {
        try {
            chatWindow.say("reading...", true);
            while(true) {
                chatWindow.say("...", true);
                System.out.println("reading");
                String line = in.readLine();
                System.out.println("line read: " + line);
        catch(Exception e) {
            System.out.println("Error while recieving message: " + e.getMessage());
}Client
public class ClientSession {
    private ChatWindow parentWindow;
    private BufferedReader in;
    private PrintWriter out;
    public ClientSession(String ip, int port) {
        try {
            Socket client = new Socket(ip, port);
            System.out.println("Now connected to " + ip + ":" + Integer.toString(port));
            out = new PrintWriter(client.getOutputStream());
            in = new BufferedReader(new InputStreamReader(client.getInputStream()));
        catch(Exception e) {
            System.out.println("Error while connecting: " + e.getMessage());
    public void sendMessage(String message) {
        System.out.println("Sending message: " + message);
        out.println(message);
        System.out.println("message sent");
    }output:
opening connection: 127.0.0.1 <- Client opening session, starting new ClientSession thread (not in code)
Now connected to 127.0.0.1:3300 <- ClienSession thread connected
Session with Client accepted <- Server accepting request from client (not in code)
reading <- ServerSession in the while(true) loop
Sending message: qdsf <- using the SendMessage function
message sent <- same function
<- nothing is said by the server =( d*mn you server!! read it!!! xD
Edited by: Dodgedog on Jul 6, 2008 5:40 PM

Similar Messages

  • I have elements 5 on a vista pc. Elements will not open I receive the message "Attempt to access invalid address". Ihave re-installed but still receive the same message. Any ideas please.

    I have elements 5 on a vista pc. Elements will not open I receive the message "Attempt to access invalid address". I have re-installed but still receive the same message. Any ideas please.

    Make sure your user account has full administrative permissions.  Then, at this stage of the game, I would take the following steps:
    - Re-create the Preferences file following these instructions:
    Re-create the Photoshop Elements preferences file to eliminate problems that a damaged preferences file might cause.
    Note: When you use this solution, Photoshop Elements will create a new preferences file and you will lose custom settings associated with your current preferences file. However, the file you rename in step 2 is your original preferences file. If you determine that the preferences file is not causing the problem, then you can restore your custom settings by undoing the instructions below.
    To re-create the Photoshop Elements preferences file:
    Quit Photoshop Elements.
    Locate the Adobe Photoshop Elements preferences files. In Photoshop Elements 5.0, there are two preferences files, one for Organizer and one for Editor:
    Users\[ user ]\AppData\Roaming\Adobe\Photoshop Elements\5.0\Organizer\psa.prf
    Users\[ user ]\AppData\Roaming\Adobe\Photoshop Elements\5.0\Editor\Photoshop Elements 5 Prefs.psp
    Rename the extension for the files (for example, to psa.old).
    Start Photoshop Elements. Photoshop Elements creates a new preferences file.
    I doubt that this will fix your problem, however, it is always the first thing to try.  If it does not, take these steps:
    - Uninstall Photoshop Elements
    - Run the Windows Installer CleanUp Utility (http://support.microsoft.com/kb/290301)
    - Reinstall Elements
    - Reinstall the 5.0.2 patch
    Good luck,
    Juergen

  • My iBooks will not open, I receive a message that states: "Failed to load book because t he requested resource is missing." How can this be repaired/resolved?

    My iBooks will not open, I receive a message that states: "Failed to load book because the requested resource is missing." How can this be repaired/resolved?

    If you can't open a particular ibook then try deleting it from the bookshelf via the Edit button at the top right of the bookshelf, and (assuming that it's still in your country's store) redownload it via the Purchased tab in the ibookstore in the app (or if you have a copy of it on your computer's iTunes library sync it back from there).

  • TS3992 my ipad is locked up and i cannot open because a icloud message will not let me in the message is that i have not backed up in two weeks but when i tap on ok it does nothing!

    my ipad will not let me open the screen to do anything due to an icloud back up message saying that the ipad has not been backed up in 2 weeks.
    When i tap ok nothing happens i cannot slide to unlock the screen to connect to the internet or for anyother function.
    Please any help will be welcomed

    Hey herbthewelder,
    I'd give these troubleshooting steps a try, they're for when your iPad appears frozen or unresponsive:
    If the device is unresponsive or certain controls aren't working as expected, try restarting
    To turn off the device, press and hold the Sleep/Wake button until the red slider appears.
    Slide your finger across the slider to turn off the device.
    To turn on the device, press and hold the Sleep/Wake button until the Apple logo appears.
    If the device remains unresponsive or does not turn on (or power on), try resetting
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds.
    You can read more about the troubleshooting steps here:
    iPhone, iPad or iPod touch: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    Cheers,
    David

  • AFTER SUBJECT IS TYPED IN THE CURSOR WILL NOT LET ME WRITE THE MESSAGE

    WHEN SENDING AN E-MAIL, I CAN TYPE IN THE CONTACT PERSON AND THE SUBJECT, BUT THE CURSOR WILL NOT GO ANY FURTHER - THEREFORE, I CANNOT TYPE MY MESSAGE
    == This happened ==
    Every time Firefox opened
    == I TRIED TO SEND A MESSAGE TODAY

    1) Firefox 2.0.0.20 is no longer supported, and since you are using Windows Vista there are 3 newer versions of Firefox you can install - 2 of which are still supported.
    2) Which '''web mail''' service are you using with Firefox?
    Yesterdays Hotmail upgrade seems to have broken many things for Firefox users, regardless of which Firefox version is used. It's up to Microsoft to fix the problems they created with that update.

  • My iPad 5 will not charge, I get the message " CHARGING IS NOT SUPPORTED WITH THIS DEVICE

    I get the message " CHARGING IS NOT SUPPORTED WITH THIS DEVICE. I've checked different cables and chargers ( from our other iPad 5, and cleaned the port, but it won't charge plugged into the computer or ghargers.

    If charging will not work with valid cables and chargers and the Lightning port is clear, there is likely a hardware issue.  Take the iPad to an Apple store genius bar and have it tested by the techs.

  • TS3988 icloud will not back up however the message stating i have not backed up in three week will not disappear or back up.  Frozen in this state

    Frozen in icloud back up.  Will not follow through with back up.  Plugged in, locked and connected.  Holding power button does not work and screen will not allow and communication by touch...

    Welcome to the Apple Community.
    Try a hard shutdown (hold down the power and home screen buttons together until it shuts down)
    If your back up continually fails, you might try turning off back up on your mobile device (settings > iCloud > storage & backup) and then deleting the backup file from iCloud by swiping the backup file on the mobile device (settings > iCloud > storage & backup > manage…) and then turning back up on again.
    Being able to back up to the cloud can be very useful, especially if you don't have access to a computer or have infrequent access to one, however unless you specifically need to use iCloud for back up, you will find backing up to iTunes significantly more convenient and possibly more reliable.

  • I am using a Mac with OS 10.9, many of the Acrobat files will not open, I receive the following message:

    Adobe Reader could not open 'Aeron_Chairs_adjustment_guide.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
    This happens very often.  Is there a setting I need to check?  I downloaded the lasted version of Reader with no change when opening a Acrobat file.
    Thanks

    How do you tell the download to save to your desktop. Please tell us EXACTLY what you click, what it says, what you do, etc. The essence of the problem is that there is more than one way to do things, so we need to know just exactly what you are doing. Also, what app do you view your mail in.

  • Fire fox will not open and give the message that program is already running when it is not and i have to restart my computer. i am running windows xp and this problem started after the last up date. i have tried uninstalling and reinstalling the program

    is this a known issue?

    If you close Firefox properly the problem will practically disappear.
    To close Firefox properly:
    :<b>Closing Firefox</b> ''(#close_firefox)'', avoid getting <b>Firefox already running</b> messages:&nbsp; To properly shutdown Firefox when multiple windows or closing the
    last window use File → Exit/Quit (or Firefox button → Exit).&nbsp; Closing Firefox with the [X] in the upper right corner closes the window ("Ctrl+W") but that does not necessarily close Firefox if it has subtasks running.&nbsp; If you want to close and reopen Firefox use the "Restart" within Add-ons if you made a change requiring a restart, or install "[https://addons.mozilla.org/en-US/firefox/addon/restartless-restart/ Restartless Restart]" ("Ctrl+Alt+R") which will allow you to take Firefox down and restart without having to check the Windows Task Manager to see if Firefox first actually ended. ([http://kb.mozillazine.org/Firefox_hangs Firefox hangs])
    In checking the Windows Task Manager be sure to check the "Process" tab not the "Application"tab/

  • I had a pop-up from Mcafee yesterday with option to block a particular access request, today Firefox will not open but shows the message with "try again" -please help.

    I assume that I inadvertantly authorized McAfee to block Firefox .
    How to unblock ?
    thanks for helping.

    Sometimes a problem with Firefox may be a result of malware installed on your computer, that you may not be aware of.
    You can try these free programs to scan for malware, which work with your existing antivirus software:
    * [http://www.microsoft.com/security/scanner/default.aspx Microsoft Safety Scanner]
    * [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware]
    * [http://support.kaspersky.com/faq/?qid=208283363 TDSSKiller - AntiRootkit Utility]
    * [http://www.surfright.nl/en/hitmanpro/ Hitman Pro]
    * [http://www.eset.com/us/online-scanner/ ESET Online Scanner]
    [http://windows.microsoft.com/MSE Microsoft Security Essentials] is a good permanent antivirus for Windows 7/Vista/XP if you don't already have one.
    Further information can be found in the [[Troubleshoot Firefox issues caused by malware]] article.
    Did this fix your problems? Please report back to us!

  • IPhone 5s will not send or receive mms/group messaging

    Hello,
    I recently got a new iPhone 5s for my birthday. Before I had a iphone 4. My carrier is verizon
    I had never been able to send pictures to friends who have non iphone phones. I also was never able to receive a group message with people who have non iPhones and iPhones. When I try to send a group message including non iphone users, it sends all messages independently. I have tried everything from turning iMessage and mms on and off to taking out my SIM card. My friend who has an iphone started a group chat with users of iphone and non iphone, though I am still not able to receive the messages even with a new phone and a new SIM card. Is this a problem with verizon? Even so my friends who receive the group chat have verizon and still get the messages. Please I need to fix this because it's extremely aggravating that a simple group messaging function does not work and that no one so far can give me answer on how to fix this. Thanks.

    Contact Verizon. Group messages in iOS send as MMS messages, which is the same thing used to send picture messages. Your account is not provisioned properly (or you do not have a plan that includes MMS messaging).

  • My ipad receives email with the hotel wifi but will not send.  The error message is "user name or password for ........is incorrect" but both are correct and unchanged.  Restarting iPad didnt help.

    My iPad receives email on the hotel wifi but will not send.  The error message reads "user name or password for smpt......is incorrect" but both are correct and unchanged.  Restarting iPad did not help.

    I did try this too, but when I access my webmail on the iPad, the iPad doesn't allow me to type my message.  I am able to enter in the "to" address and the "subject" line, but then the keyboard will not come up for me to type my message.  Is there some trick to this?  Very frustrating!

  • My gmail account receives mail, but will not send, forward, or reply...it gets stuck in the spin and then I have to force quick firefox.

    My gmail accounts receives mail, but will not send, reply or forward. Also cannot open settings. It gets stuck in spin mode.
    I worked with an apple tech, tried several things, and then she suggested I contact Mozilla support.

    Hey Butterworth,
    You may need to use the information in this article to help you troubleshoot the issue with your outgoing server:
    OS X Mail: Troubleshooting sending and receiving email messages
    http://support.apple.com/kb/ts3276
    Thanks for coming to the Apple Support Communities!
    Cheers,
    Braden

  • Thunderbird will not send or receive email in Windows 8.1 unless I re-install. The next time I open Thunderbird it is again broken.

    Thunderbird will not send or receive email in Windows 8.1 unless I re-install it. The next time I open Thunderbird it is again broken. So, I have to repeat the un-install / re-install process. Currently I am using Version 31.0, but this was happening the the previous version as well.
    Here are some of the messages in the error console:
    Could not read chrome manifest 'file:///C:/Program%20Files%20(x86)/Mozilla%20Thunderbird/chrome.manifest'.
    Could not read chrome manifest 'file:///C:/Program%20Files%20(x86)/Mozilla%20Thunderbird/extensions/%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D/chrome.manifest'.
    Timestamp: 8/3/2014 8:02:29 AM
    Warning: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
    Source File: resource://gre/components/steelApplication.js
    Line: 783
    Timestamp: 8/3/2014 8:02:57 AM
    Warning: Use of getPreventDefault() is deprecated. Use defaultPrevented instead.
    Source File: https://www.mozilla.org/thunderbird/js/jquery/jquery-1.5.1.min.js
    Line: 16
    Thanks for the help.
    Joe

    That really sounds like anti virus scanning to me. Try rebooting your machine into safe mode with networking and see if it works correctly then.

  • My iphone 4 will not send and receive text messages at random times

    My iphone 4 will not send and receive text messages at random times.  My brother has the same phone, lives in the same home and doesn't have this problem.  I can't receive messages without my iphone displaying a message asking for my phone number at random times. It happens intermittently.  Does anyone know why this happens? I am referring to regula text messages not imessages.  I have turned it off and also updated to the most recent software. thanks

    I've been an AT&T customer since they were under different names in the 90s and have never heard/seen that. I would check with them. I'd really like to see that error. To get a screenshot on the phone, press the home button and sleep/wake button together quickly and release. You will see the screen flash slightly and hear the camera shutter noise.

Maybe you are looking for

  • Is there a way of moving imported images in lR4 from mac HDD to and EX HDD with out loosing LR4 data

    Hi i've managed to fill my mack up with images as i imported all my photos to the MAC HDD rather than an external HDD,,,school boy error :\   (but i am new to lightroom) as there's 30,000+ is there a way of moving them with out having to reload them

  • Filenames of photos I send via Iphone to for example Outlook

    When I e-mail a photo from my Ipad or Iphone to my PC or MacBook the filename is always equal like image1 image2 image3. Next e-mail: image1, image2. So after saving photo's from e-mail one, I have problems with the namings of the photo's from e-mail

  • 6500 Slide + Mac = Update Issues

    I'm wanting to update the firmware on my 6500 Slide, I'm on a Mac. I have BT, and the update section on my phone allows me to update using BT. I just can't find the darned software to download. The beta Mac software doesn't support this phone... LOL.

  • Time of Po replication to R/3

    Hi experts Is there some to know the exactly time of a PO was replicated to R/3 tHANKS Nilson Fonseca

  • CISCO ACS, How to Limit User Session ?

    Hi Guys, hope you would help me, how to limit the user session in ACS 5.x ? i'm aware the menu on Access Policies >Max User Session Policy > Max Session Group Settings i already set the global value to 1, Max Session for User in Group to 1, and Max S