Socket stuff... Connection works but neither client nor server will receive

Okay, here's the deal...
I have a serversocket and a clientsocket in the same program. I have the client connect to 127.0.0.1 and the server accepts a connection. Both server and client make a thread to listen to one another. Then the server sends something to the client. The client doesn't catch anything. When I use the client to send to the server, the server also doesn't catch anything. Also, when I add the line "System.out.println(fromServer.readln())" after the connecting instead of in a separate thread, it gets totally weird and starts jumping back and forth between lines within the same try block. The line order gets random and some get executed twice. I'm using the IntelliJ software to program / debug. The application always gets stuck at the line I mentioned before. . I have no idea what the hell is going on. Can any one please please help me? =(
P.S. I could add the code but I'm not sure what to add and if I added all of it it'd kind of be a lot so... if you need to take a look at it tell me what parts you want or if you want the full thing or whatever. I don't see a way to attach files to posts =p otherwise I could have attached the project.

try this:
Client:
import java.io.*;
import java.net.*;
public class client
     Socket soc;
     DataInputStream in;
     PrintStream out;
     public client()
          String str="";
          try
               soc = new Socket("127.0.0.1",5432);
               in = new DataInputStream(soc.getInputStream());
               out = new PrintStream(soc.getOutputStream());
               while((str=in.readLine())!=null)
                    System.out.println(str);
               in.close();
               out.close();
          catch(Exception e)
               System.out.println(e);
     public static void main(String args[])
          client obj = new client();
}Server:
import java.io.*;
import java.net.*;
public class server
     ServerSocket ss;
     Socket soc;
     DataInputStream in;
     PrintStream out;
     public server()
          String str="";
          try
               ss = new ServerSocket(5432);
               while(true)
                    soc = ss.accept();
                    in = new DataInputStream(soc.getInputStream());
                    out = new PrintStream(soc.getOutputStream());
                    out.println("Connected !!");
          catch(Exception e)
               System.out.println(e);
     public static void main(String args[])
          server obj = new server();
}

Similar Messages

  • On my iPad2 the swoosh sound is checked in Settings but neither it nor the jingle when the battery is being recharged now work

    On my iPad2 the swoosh sound is checked in Settings but neither it nor the jingle when the iPad is connected for recharging are working. Any ideas ?

    Ensure that the mute switch is not activated. If it is not be sure the volume is at a level in which you can hear it. If your still having issues, test the sounds in other applications. If it is affecting multiple things, you may want to attempt a reset by holding the lock/power button and the home button until you see an Apple logo.

  • I downloaded iOS 7 onto my iPhone 4 and updated the iTunes on my PC, WiFi connection works but somewhow it won't do anything when I plug the iPhone.

    I downloaded iOS 7 onto my iPhone 4 and updated the iTunes on my PC, WiFi connection works but somewhow it won't do anything when I plug the iPhone. Now, I got frustrated that neither iTunes nor my iPhone do anything. I need my iPhone to get it back to work regardless if it's back to the last version of iOS.

    I just encountered this problem for the first time and stumbled upon this forum to find a solution.  I played around with it a bit and it seems that if you slide your finger from the bottom up, you will come upon that new screen that will allow you to do various functions with your phone (put it in airport mode, lock, etc.), you can select your Airport from this screen and play your music wirelessly from your phone; at least this was my experience. Hope this helps!

  • I have a new Macbook Pro - trying to migrate files etc from my Macbook Air using a Thunderbolt Cable between the two.  I follow the directions but the two computers never "discover" each other.  WiFi connect works but 70 hours is a rough deal.

    I have a new Macbook Pro.  Trying to migrate files etc from my Macbook Air using a Thunderbolt Cable between them.
    I follow the directions but the two computers never "discover" each other - using a WiFi connection works but 70 hours is a rough deal.
    (Mac OS 10.8.2 on both computers)

    Are you trying target disk mode?
    http://support.apple.com/kb/PH10725
    Ciao

  • DW CS3: test connection works, but local pages won't upload.

    My MacBook Pro died, can'taccess files or apps and I don't have the CS3  install disks,  so I moved DW over from my Mac Pro.The test connection works, but local pages won't upload.I re-entered all the site info, confirmed I ahd all the correct FTP settings from my sertver tech guys. I even created a new site duplicating all the original info. BTW I have ALWAYS had this problem on the Mac Pro...Never been able to upload from that computer. All the other apps in CS3 work fine.
    jackhatfield

    FileZilla worked. Thanks so much. Still wish I could figure out why
    Dreamweaver won¹t transfer files, it would be easier than editing in DW and
    then having to use Filezilla to transfer them. DW never transferred files on
    the Mac Pro I had it installed on either (that¹s where I got it from when I
    moved apps to my new MacBook Pro).
    jack

  • Photoshop Elements 12 and Premiere 12 both install, but neither of the Editors will launch.

    Photoshop Elements 12 and Premiere 12 both install, but neither of the Editors will launch.

    what os and what do you see when trying to start photoshop elements 12?

  • Neither dreamweaver nor photoshop will update.  I get this error for both, "U44M1P7"

    Neither dreamweaver nor photoshop will update.  I get this error for both, "U44M1P7"

    Try downloading the updates from http://www.adobe.com/downloads/updates/ and install them manually.

  • I would like to know which apple server dictation connects to so that my proxy server will stop blocking it. Which apple server does it connect too?

    I would like to know which apple server dictation connects to so that my proxy server will stop blocking it. Which apple server does it connect too?

    I would presume so, but it might be worth your while to experiment and play around with different combinations to see if you can block FaceTime while keeping Game Center open.  Good luck!

  • While my iPod touch was connected to a speaker dock, I found it very hot. Not it will not turn on. I have tried the reset options and they do not work. Neither iTunes nor any of my computers recognizes it when I plug in the usb. Is there a way to fix?

    Now it will not turn on. I have tried all the reset instructions with no luck. Neither iTunes nor any of my computers will recognize it when I plug it in. Is there any chance to get it working or am I out of luck? Please help if you can since I cannot afford to purchase a new one at this time. Thanks.

    Your iPhone is in recoverty mode at the moment so to possibly get it back up and running you would need to do a restore as you have been trying. Follow the steps in the article below for the specific error messages you have been receiving. If after following all steps the issue remains book an appointment at a local Apple Retail Store to have the iPhone evaluated.
    Resolve specific iTunes update and restore errors

  • Connection works but program does not continue in the code ?

    Hello,
    I have a client, a server and a data class implementing Serializable interface.
    Both classes communicate via sockets.
    Between the sockets I transfer objects from the type of the data class.
    The client and the server are running each in a Thread.
    First the server is started then pressing a certain button in the GUI the client is started.
    1. Why is the code in the clients Thread never going beyond this code line: System.out.println("test"); ???
    2. Why is the file satz.dat not written ?
    This is the part code of all 3 classes which is making me trouble:
    Client code:
    public class ClientThread extends Thread
           ClientThread()
           public void run()
                try
                     InetAddress ip = InetAddress.getByName("localhost");                 
                     Socket socket = new Socket(ip , ServerThread.PORT); 
                     System.out.println("test");
                     ObjectInputStream incomingObject = new ObjectInputStream(socket.getInputStream());             
                     ObjectOutputStream outgoingObject = new ObjectOutputStream(socket.getOutputStream());                    
                      outgoingObject.writeObject(serializeObjekt(meineBuchdaten)); // serialize the object "meineBuchdaten"
                      incomingObject.close();
                      outgoingObject.close();
                      socket.close();              
                catch (Exception e)
                      e.printStackTrace();                
    Method to serialize the string data of the data class called Buchdaten class:
    public Object serializeObjekt(Object objekt) throws IOException
              ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("d:/satz.dat")));
             oos.writeObject(objekt);
             oos.flush();
             oos.close(); 
             return oos;
    server class:
    public class ServerThread extends Thread
         public static final int PORT = 8080;
         private ServerSocket myServerSocket = null;
         private Socket myClientSocket;     
         private Database myDatabase = new Database();     
         public ServerThread()
        public void run()
              try
                   myServerSocket = new ServerSocket(PORT);               
              catch (IOException e)
                   e.printStackTrace();
              System.out.println("Started: " + myServerSocket);          
              try
                   while(true)
                        // Warten until the client connects...               
                        myClientSocket = myServerSocket.accept();     
                        System.out.println("Connection done - handshake " + myClientSocket);
                        ObjectInputStream incomingObject = new ObjectInputStream(myClientSocket.getInputStream());
                     ObjectOutputStream outgoingObject = new ObjectOutputStream(myClientSocket.getOutputStream());                    
                        Buchdaten bd = (Buchdaten) incomingObject.readObject();
                        System.out.println("This should be the deserialized data: " + bd);
                        myClientSocket.close();                    
              catch(Exception ex)
                   System.out.println(ex.getMessage());
    data class:
    public class Buchdaten implements Serializable
         private static final long serialVersionUID = 1L;
         private String autor;
         private String titel;
         private String jahr;
         private String verlag;
         private int number;
         private int id;
         public Buchdaten()
         public void setDataToArray(String autor, String titel, String jahr, String verlag , int number)
           this.autor = autor;
           this.titel = titel;
           this.jahr  = jahr;
           this.verlag = verlag;
           this.number = number;     
         public void setDataToArray(int number , int id)
           this.number = number;     
           this.id = id;
         public void setDataToArray(String autor, String titel, String jahr, String verlag , int number , int id)
           this.autor = autor;
           this.titel = titel;
           this.jahr  = jahr;
           this.verlag = verlag;
           this.number = number;     
           this.id = id;
    }

    >
    Oh, and by the way, is there a reason you aren't just using normal java RMI?
    Edited by: jtahlborn on Feb 1, 2008 9:34 PMOh, and by the way, is there a reason you aren't just using normal java RMI?
    yes for now i have to do it this way. The app must only run on my home pc but later i have to do it with RMI, but first it must work with sockets and streams etc stupd i know... ;-)
    sabre150: quote:"As with all two way communication, one thread should be used for writing and another for reading. This ways the blocking nature of the streams works for and not against."
    0: Does that mean i have to open 4 threads ? 2 threads for the client class and 2 threads for the server class? each one has an ObjectInput/Output - stream right?
    For now i have only opened the outputstream on client side and the inputstream on server side to see wether it works at all. Furthermore my object is now serialized to the satz.dat file and it works.
    1. Is there a way to serialize my data "meineBuchdaten" on-the-fly without writing it into a file on harddisk?
    2. I want to print out the deserialized data but it doesnt work i get no output using the system.out.println method?
    3. After this output: Connection done - handshake Socket[addr=/127.0.0.1,port=3139,localport=10001] I get this output: null
    why null? from where does this null come?
    Edit: ok my debugger work now again i reinstalled eclipse... debugging the cast into "meineBuchdaten" is the problem because right after this the debugger jumps into an exception this one
    catch(Exception ex)
                   System.out.println(ex.getMessage());
              }Edit: I have changed again the code a bit only this:
    // Output of the deserialized data for test purposes
    System.out.println("This should be the deserialized data: Autor: " + bd.getAutor());
    its accessing the autor attribute variable of the bd object in a proper way but still the bd object is null i guess the problem is my serialized data on the client side is not transported what do i wrong can someone pls help me please ?
    changed code:
    client class:
    public class ClientThread extends Thread
           ClientThread()
           public void run()
                  try
                          InetAddress ip = InetAddress.getByName("localhost");                 
                          Socket socket = new Socket(ip , ServerThread.PORT); 
                          System.out.println("test");                
                           // ObjectOutputStream for the object to be sent over socket to the server
                          ObjectOutputStream outgoingObject = new ObjectOutputStream(socket.getOutputStream());
                          // writing the class object "meineBuchdaten" into a file on the hard disk
                          try
                               ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("d:/satz.dat")));
                          oos.writeObject(meineBuchdaten);
                          oos.flush();
                          oos.close();
                          catch (NotSerializableException nse)
                               System.out.println("No Serialization of the class " + nse.getLocalizedMessage() + " is possible");                           
                          catch(IOException ioe)
                               System.out.println(ioe.getMessage());
                          // closing the ObjectOutputStream and the client connection to free resources
                           outgoingObject.close();
                           socket.close();              
                     catch (Exception e)
                           e.printStackTrace();                
    server class:
    public class ServerThread extends Thread
         public static final int PORT = 10001;
         private ServerSocket myServerSocket = null;
         private Socket myClientSocket;     
         private Database myDatabase = new Database();     
         public ServerThread()
        public void run()
              try
                   myServerSocket = new ServerSocket(PORT);               
              catch (IOException e)
                   e.printStackTrace();
              System.out.println("Started: " + myServerSocket);          
              try
                   while(true)
                        // wait until the client connects...               
                        myClientSocket = myServerSocket.accept();     
                        System.out.println("Connection done - handshake " + myClientSocket);
                        ObjectInputStream incomingObject = new ObjectInputStream(myClientSocket.getInputStream());                
                        // Reading the serialized data and cast it to the proper type
                        Buchdaten bd = (Buchdaten) incomingObject.readObject();
                        // Output of the deserialized data for test purposes
                        System.out.println("This should be the deserialized data: " + bd);
                        // closing the ObjectInputStream and the client connection to free resources
                        incomingObject.close();
                        myClientSocket.close();                    
              catch(Exception ex)
                   System.out.println(ex.getMessage());
    }Edited by: pel on Feb 2, 2008 2:04 AM

  • Time Capsule: Wired connection works but cannot connect via wifi to net

    Hi all,
    I've had a Time Capsule for a year or so. I've been having problems with connectivity over recent months and I'm not sure where the issue is.
    I have plugged in an ethernet cable joining my MBA to the TC, and another from the TC to the wall socket. I can access the internet without any problems.
    However, if I unplug the ethernet cable from my MBA (or indeed if I don't plug it in in the first place) then I cannot connect to the internet. I can still back up to Time Machine etc., but nothing can get 'through' the TC.
    Also, if I turn Mobile Data off for my iPhone, I cannot then access the internet via WiFi through the TC.
    Any ideas as to how to fix this? The TC is in bridging mode, which has worked fine before. All suggestions welcome!

    Ok.. let me try again..
    Going back to your first post.
    I have plugged in an ethernet cable joining my MBA to the TC, and another from the TC to the wall socket. I can access the internet without any problems.
    However, if I unplug the ethernet cable from my MBA (or indeed if I don't plug it in in the first place) then I cannot connect to the internet. I can still back up to Time Machine etc., but nothing can get 'through' the TC.
    When you plug in via ethernet the MBA works but not by wireless..
    Now add that to the new info.
    The campus network relies on each PC's individual MAC address and then assigns IP addresses as required;
    Is the MAC address actually registered?? Because the MAC address of the ethernet port of the MBA and the MAC address of the wireless are different.
    If the MAC addresses are not registered.. how does the Uni know the difference between a computer and a router??
    You are not allow to run a router that feeds DHCP into the uni system.. but they cannot know what you have behind the MAC address of the item plugged in. A computer or a router.
    So the TC has to be in bridging mode - which has worked perfectly well previously
    Try releasing the MAC address to the PORT.. because the uni might have decided they don't want hubs connected either.. therefore the address of whichever device that is plugged into the wall is registered at the switch and will not allow a change for a fix period.. that is one way to stop people changing stuff around.
    Try powering off the TC.. when you use another item.. or change from ethernet to wireless.. then power up the TC again and then power up the device .. eg the wireless on the laptop.. If it fails, it is not the TC that is causing it.. because in bridge the TC is completely dumb. It has no ability to control the MAC address being sent to the main router. None whatsoever.
    If your TC recently upgraded to 7.6.4 firmware.. though.. well it can do all kinds of nasties.. flash it back to 7.6.1 and factory reset it.. and hope it works as it did before.. if not the uni changed the system to prevent your TC acting even as a hub.

  • My WiFi & Ethernet connection works but automatic is not working

    The settings for my networking have gone kuh fluee (sp???) since I got up and running on my brand new MBP with 10.5.1 (and yes, I've installed all of the updates).
    I have 3 locations set up (or I thought they were set up as they worked on my old PB):
    WiFi
    Ethernet
    and then there's AUTOMATIC
    Both my WiFi and Ethernet work fine. I want the Mac to understand that if Ethernet is connected, go and use Ethernet; if no Ethernet, then use the WiFi. I thought this would work when the location is switched to AUTOMATIC. AUTOMATIC simply just can't seem to connect. It continues to show all lights green except for the NETWORK light. I restart the modem and router over and over and the Networking thing just keeps telling me to do that again. Ok - what am I NOT getting here. Again, note that both ethernet and WiFi connection as separate locations work; what is NOT working is AUTOMATIC and I want that to work so that the Mac "automatically" detects what is out there for me to connect and if Ethernet, it connects via Ethernet.
    Insight? Solutions? Advice???

    The following is an excerpt from The Peachpit Learning Series for Leopard but I am sure it applies to Tiger and probably Panther as well. I have four computers at home, three with Leopard and one with Tiger. One Tiger machine is connected to my Airport Extreme via ethernet and my other desktop runs Leopard and also is connected via ether net. My two laptops are connected via Airport.
    Open network preferences via System Preferences. You'll see the network window which should list your networks on the left had side of the page in the order of preferences what you might want to do and your individual computer is change that order of preferences to Ethernet first and Airport Second, that way if you are connected via ethernet it will connect that way. If you are not connected via ethernet it will look for the ethernet connection first and not seeing one, it will move on to Airport. You can change the order of preferences by clicking the activity button at the bottom of the window on the left that looks like a little cog wheel and then set service order.
    I'm not 100 percent sure but by choosing automatic it either tells the system to do the above automatically when you open your browser or email to it means go to your wireless system of preference.
    Hope this helps.

  • Wireless network connection works, but browsers don't

    Wireless connection worked before. Now it shows the wireless connection is strong, but when I open a browser (explorer or firefox) it gives me the error that server can't be located. When I do a test of an application to run on a browser (where the connection shouldn't matter) I still get error message. When running Os X, the connection/browsers are fine. Have Service pack 2.
    any ideas? thanks!

    this is the same problem i am having with my xp side i am not getting the correct ip address and looking for a way to obtain the correct ip address not the one it is creating.

  • I want to buy the camera connection kit but not sure if it will work with my camera it's a Sony dsc w35 can anybody help..

    I want to buy the camera connectivity kit for my iPad 3  but not  sure if it will work with my Sony dsc w35 camera can anybody help.

    That camera does not have an SD card. It uses Sony's Memory Stick™ DUO Media.
    The camera does provide for USB connection, however, some cameras require too much USB power from the iPad. Suggest you take your iPad to a camera store and ask to test it with your iPad.
     Cheers, Tom

  • Wired Connection Works, but Wireless won't connect

    I just got the Wireless-N Broadband Router and I have my Home computer connected to it through a LAN connection. And I have an internet connection. But on my Laptop the only thing that my WiFi connection picks up is HPsetup (Is this my Linksys Router?).. The Hpsetup has a very low connection by my Linksys Router. And the signal fades in and out.

    what Conection protocol does your Laptop use?
    PreN, 802.11g, 802.11b?
    Regards Simon
    NAS: TS-459 Pro - 3.6.1 Build0302T - 4 x 1TB Samsung HD103SJ : EXT4 - APC ES 700VA UPS
    QPKG: WordPress 3.4, TwonkyMedia 6.0.39 QPKG - Zenphoto1.4.2.1 [7802] - phpMyAdmin v3.3.10
    Network: Netgear DG834G V4.01.40 - DGTeam Rev. 0849 -> Cisco RV220W 1.0.4.13, Cisco SLM2008, Dlink DSM-520, Xbox360

Maybe you are looking for

  • PS3 (Playstation 3) issue not loading BDR Bluray | Adobe Encore CS6

    I recently created a Bluray using Adobe Encore CS6, and the Bluray is not loading on my PS3, but is working fine on my other player (LG, Toshiba and PC).  Does anyone have the same issue and found a solution?  I need help on this as most of my client

  • Issue in the table settings of the screen.

    Hi Expert, I have an issue because some users are changing the Table Settings of the screen to display the sales orders. So if somebody make a change affect to all the systems so I want to find a way in order to limit the access to this setting. Than

  • Can't Uninstall/Install Quicktime...

    Basically, I want to uninstall my old version of quicktime. I basically corrupted it (I believe) because it won't open. When I remove the app from my mac, it's no longer there. However, whenever I'm trying to re-install using the official Quicktime 7

  • HT4759 every time save a new contact dont Shows in Outlook 2007

    every time save a new contact dont Shows in Outlook 2007

  • Error installing SAP 4.7 IDES MDB-06029 caught exception

    Hello Gurus, Let me appreciate all your help and support for new guyz like me. I am trying to install the SAP 4.7 IDES on a system Configuration: --250 GB HDD --2 GB DDR RAM -- 2.4 GHZ celeron processor -- Win 2K SP4 OS during installation installed