Sockets & inetd

Hello!
It all worked just fine before I used inetd to start the server. When I use inetd I get this exception:
Network error: Address already in useSo, the inetd-stuff works, because the server is started, but...
This is my code:
Client:
public class Client {
    private int port = 7654;
    private String host = "ausone";
    ObjectOutputStream out = null;
    ObjectInputStream in = null;
    public Client (String host, int port) {
        this.host = host;
        this.port = port;
        setup ();
    private void setup () {
        try {
            Socket s = new Socket(host, port);
            System.out.println ( "Connected to: " +s.getInetAddress().getHostName() );
            out = new ObjectOutputStream (s.getOutputStream());
            in = new ObjectInputStream (s.getInputStream());
            } catch (IOException e) {
                System.out.println ("Could not connect to socket: "+e);
Server:
public class Server {
    private ServerSocket server;
    public static final int DEFAULT_PORT = 7654;
    public static void main(String[] args) {
        Server tcserver = new Server();
        tcserver.runServer();
    private void runServer() {
        ServerThread newServerThread = null;
        Socket newSocket = null;
        try {
            server = new ServerSocket (DEFAULT_PORT);           //<------ Here!!
            while (true) {
                System.out.println ("Waiting for client connection");
                for(int i = 0; i < 10; i++) {
                    newSocket = server.accept ();
                    newServerThread = new ServerThread (newSocket,i);
                    newServerThread.start ();
        } catch (EOFException eofException) {
            System.out.println ("Client terminated the connection.");
        } catch (IOException ioException) {
            System.out.println ("Network error: " + ioException.getMessage());
    private class ServerThread extends Thread {
        Socket connection = null;
        private ObjectOutputStream out;
        private ObjectInputStream in;
        public ServerThread(Socket socket, int num) {
            connection = socket;
            out = new ObjectOutputStream (connection.getOutputStream());
            in = new ObjectInputStream (connection.getInputStream());
            //send client answer
            try {
                String result = "testing";
                out.writeObject (result);
            } catch (IOException e) {
                System.out.println ("IO Error "+e);
}So, what is wrong!!!
And, another thing I noticed was that I can't use ObjectInputStream anymore, then I get a InvalideStreamHeader... or something like that.
Please! I really need some help...

Thanks for your answers, I'm sorry for my late reply.
I have one more question for you Sylvia.
Perhaps it's just me not knowing the best way to solv
my problem, it's like this: Under my applet, I have
native codes and libraries, I don't know if that makes
it any different. The problem is that if two or more
users connect to the server at the same time the
server-code "crashes". So I need separate processes (I
think), and I thought that using inetd was the way to
do it. Otherwise, how will the server know to which
user it will send the answer? Please correct me if I'm
wrong!
LinaLina, sounds like your native code is not thread safe. If fixing that is not an option, then you're probably right that you'll need separate processes. If you want to run things from inetd, then just skip all the socket handling stuff, and treat System.out as the OutputStream you would have got from the socket, and System.in as the InputStream you would have got.
It's usual in such circumstances to provide a command line option that tells the program whether to listen on a socket first, or just go straight into processing the connection it gets from inetd. That makes development a lot easier.
That said, starting a VM is very expensive, and each one takes a lot of memory. One possible alternative is to seperate out the native code into a seperate c/c++ program that can be invoked from the Java VM, and communicated with using sockets. How practical that is depends on the extent of the natiive API, and the frequency of calls to it.
Sylvia.

Similar Messages

  • Windows: Passing Sockets Between Processes?

    I've done a bit of looking around, and for the most part, it seems to be impossible to pass sockets between separate windows processes -- since a socket only exists inside one process, and it's not serializable, etc. Apparently, *nix operating systems will store a socket in file descriptors after a process exits, so it's possible to transfer sockets, but not on a Windows OS.
    So, I just want to ask: am I missing anything? Is there some way to:
    a) transfer sockets between processes (at least within a local network) or
    b) dynamically reload the bytecode of a process, without dropping sockets? IE, some sort of "server copyover-reboot" is what I'm going for.
    So, is it possible, or does Windows just fall behind on this one?

    Understood... but, exactly how in the heck would one go about passing sockets from the parent process? I tried it out a bit, and System.inheritedChannel() always seems to be returning null in the child process, even though the parent waits to close its sockets until after the child has started and invoked the method.
    Edit:
    Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start", "java", "ServerMain","reboot"});
    Would this be causing in issue? This is my execution of the new process, and it first invokes cmd /c start so that it opens in a new cmd window. Would it be sending its channels to that process, and complicating the process of ServerMain's new process inheriting the channels?
    Edit again:
    I'm starting to assume that my Runtime.exec is closing the file descriptors, so it's generally impossible to pass them to the subprocess. The current System.inheritedChannel() seems as if it was made to work with inetd, and not much else.
    Message was edited by:
    cmc5788

  • Socket Security Error 2048

    Hi,
    I'm trying to make a socket connection using AS3. I am aware
    of the new Security policies. I've read all the articles and set up
    a socket policy file server and a socket server to handle the
    socket.connect().
    Im calling
    Security.loadPolicyFile("xmlsocket://myhost.com:843") but
    continually get this message in the debugger:
    Error: Failed to load policy file from
    xmlsocket://myhost.com:843 // why did it fail?? the file is there
    and port is open
    and then:
    Error: Request for resource at xmlsocket://myhost.com:11500
    by requestor from
    http://myhost.com/myswf.swf
    has failed because the server cannot be reached. // why can't the
    server be reached?? the port is open
    I've made sure I have no firewall blocking the port, no
    SELinux enabled policies, and I've verified port 843 and 11500 are
    actually open using a custom php script.
    Also when I type nmap localhost port 843 shows up as open
    using tcp. It does however say that the service is unknown. I don't
    understand that since I have edited the /etc/services file and
    created the service "flashpolicy" in /etc/xinetd.d and restarted
    inetd using: /etc/rc.d/init.d/xinetd restart.
    Heres the string my socket policy file server is suppose to
    return when it receives <policy-file-request/> :
    <cross-domain-policy><site-control
    permitted-cross-domain-policies="master-only"/><allow-access-from
    domain="myhost.com" to-ports="11500"
    /></cross-domain-policy>\0
    Can anyone give me some clues as to what I'm doing wrong? I
    think I've read every article out there regarding this subject. I
    even see that there are two bugs listed for the flash player:
    http://bugs.adobe.com/jira/browse/FP-67
    and
    https://bugs.adobe.com/jira/browse/FP-269.
    But it seems likes someone out there has achieved socket
    connections with AS3.
    Thank You

    You might try to force Flash to load the policy file first:
    Security.allowDomain(“*”);
    Security.loadPolicyFile(“http://server.com/crossdomain.xml”);

  • Systemd socket launching service and failing

    I'm creating an AUR package for poppassd (POP3 Password Changing Service). The application runs in command line using stdin/stdout but is intended to be run using xinetd and pipe the socket as I/O. The code works fine when I run via command line
    $ sudo /usr/bin/poppassd
    200 poppassd
    QUIT
    500 Username required
    $
    When I start the socket
    systemctl start poppassd.socket
    the socket opens and when I try to use telnet to connect I get a disconnect right away and journalctl reports the service exited with a status of 1/FAILURE
    Any ideas why the following service and socket files are not working?
    poppassd.service
    [Unit]
    Description=POP3 Password Change Service
    [Service]
    ExecStart=/usr/bin/poppassd
    StandardInput=socket
    StandardOutput=inherit
    StandardError=journal
    poppassd.socket
    [Socket]
    ListenStream=0.0.0.0:106
    [Install]
    WantedBy=sockets.target

    Note: i've never used poppassd and have not tested what i am about to suggest.
    Since poppassd is written to be invoked by inetd with the nowait flag, it probably wants to be started with an accepted socket, not a listening socket. To do this in systemd, first add the following to the [Socket] section of poppassd.socket:
    Accept=true
    Then change the name of poppassd.service to [email protected]
    Some socket activated template services (ie. [email protected]) also prepend '-' to the ExecStart value to prevent a single failed instance from throwing the service into a failed state.

  • Systemd socket deactivation

    systemd has an interesting feature. We can systemctl enable cupsd.socket. No cupsd server is running until I actually print something which automatically activate the server. The same are true for other services. But is it possible to stop the service automatically if I not run it for some amount of time. For example I would like that the cupsd server stop if I have not printed anything for, say 5 minutes.

    sshd does not have socket activation in the systemd sense. sshd offers sshd.socket and a matching [email protected], which offers inetd style activation.
    You really do need to patch daemons to support proper socket activation (see the daemon(7) manpage). mpd supports it, cups supposedly supports it. udev definitely supports it. lighttpd does not.

  • Problem with socket and Threads

    Hi,
    I have coded a package that sends an sms via a gateway.
    Here is what is happening:
    * I create a singleton of my SMSModule.
    * I create an sms object.
    * I put the object in a Queue.
    * I start a new Thread in my sms module that reads sms from queue.
    * I connect to sms gateway.
    * I send the sms.
    * I disconnect from socket! This is where things go wrong and I get the following error (see below).
    I have a zip file with the code so if you have time to take a look at it I would appreciate it.
    Anyway all hints are appreciated!
    //Mikael
    GOT: !LogoffConf:
    mSIP Kommando var: !LogoffConf
    CoolFlix log: MSIPProtocolHandler;setLoggedin(false)
    We got LogOffConf
    Waiting ......for thread to die
    java.net.SocketException: Socket operation on nonsocket: JVM_recv in
    socket input stream read
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:116)
    at
    sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:405)

    Off the top of my head, probably the garbage collector cleared your SMSModule coz all classes loaded through other classloaders will be unloaded when that classloader is unloaded.
    mail in the code if you want me to look at it with greater detail.

  • Can i use the same socket to connect to more than one servers

    hi,
    I'm new to java. I want to know whether a socket created using Socket() constructor can be used to connect to multiple servers, not necessarily at a particular point of time. ie, i want to connect to various servers using a single socket and register some info abt them, possible using a loop, one by one. I use connect() method to connect to particular server.
    In other words is Socket class is mutable.
    Edited by: itsraja on Feb 25, 2008 5:50 AM

    In short, I don't think so.
    Setting the server name for a socket is in the constructor.
    Socket s = new Socket("localhost", 501);I don't believe that there are any functions, such as:
    s.setHost("localhost");
    s.setPort(501);However, JavaDocs suggests that when you use the no-args constructor, your class becomes an automatic SocketImpl class, but you can't reach any of its variables unless you derive from the class, itself. But that's probably a bigger headache than it's worth.
    Now TECHNICALY, if you didn't want to create a new variable, you could use:
    Socket s = new Socket("localhost", 501);
    s.close();
    s = new Socket("remotehost", 502);
    s.close();However, this is still creating a new instance and thus a new object in memory.
    I hope this answers your question.
    Let us know exactly what you're trying to do for a more exact answer.
    ~Derek

  • My iPod Touch will no longer charge from a wall socket, only my computer. HELP!

    My 4th generation iPod Touch will no longer charge from a wall socket, only my computer. I tried buying a new cable and USB charging socket (and I bought one made by Apple), but that did not fix the problem. I restored it from iTunes, hoping that would work as well, but that failed. I am at my wit's end. Can anybody here help me? I've bought new equipment, tried rebooting, restoring, etc. but nothing so far has proven successful. If anyone's got a solution, please help!
    Thanks!
    Signed, a very frustrated iPod user in Ohio!
    <Edited By Host>

    All I can suggest is the standared fixes. It seems very strange
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem. Bring the cable and Apple wall charger too.
    Apple Retail Store - Genius Bar                                      

  • MSI K7N2 Delta-ILSR Nforce2 (Socket A) Motherboard (MB-003-MS) Features NF2 chip

    I tried to install 3 of the Crucial Ballistix Tracer (1 Gig Each) in this motherboard (MSI K7N2 Delta-ILSR Nforce2 (Socket A) Motherboard (MB-003-MS) Features NF2 chipset) and it will not run stabilly no matter what I tried. Is this a bios conflict with the memory? If so, are there any new bios updates? I have tried cas settings and voltage settings but nothing works. It will how ever run perfectly with only 2 sticks in single channel mode. It will not run same 2 sticks in dual channel mode. Anyone have any ideas? Anyone know of any new motherboards with maybe NFORCE 4 Chipset that support all 3 sticks of this memory and an AGP graphics card? Im thinking of a new motherboard but I still need to have AGP and SATA.
    Barton 3200 core proc.
    System has ran fine for a solid year until I tried new memory. Please help!

    Quote from: freakytiki4u on 07-November-06, 23:42:33
    Ok I tried to use relaxed FSB by -10 and relaxed mem timings but still unstable due to the motherboard trying to use dual channel memory. If you can modify the bios to where it will not have the capability of dual channel memory I truly believe it will work. Will u try this for me? I would greatly appreciate it as I am really not ready to spend all the money on new equipemtn when this suits my needs for now.
    sure but as i said before this is gona be experimental and risky. Here we go:
    MSI K7N2 Delta ILSR Experimental MOD E1(Disable Dual CH ability)
    Procedure is automated in best possible safest way to BIOS update.
    Prepare a blank diskette in a good condition(newest one etc.)
    ]execute file under XP will make bootdisk with automated BIOS update procedure. when diskette is ready, reboot PC and boot from FDD(floppy), wait a bit, then you will be asked for final confirmation about BIOS update process, press a key to proceed, after BIOS update is complete, ensure that you got successfully output message from flash program. then power down your PC, remove power cord from the PSU, hit power button several time to drain caps electrify, touch with hands some metal for ES discharge, and Clear CMOS.
    pull back power cord, power up your PC, when you see CMOS checksum error,(expected msg) hit F1 to continue to re-build DMI pool data, then reboot and enter in BIOS, LOAD BIOS DEFAULT, and SAFE AND EXIT.
    NOTE: Ensure your PC is stable before proceed with BIOS update.
    NOTE: Use it at own risk, chance of failure is big, cannot guarantee results and safest as provisional mode which can guarantee it will work stable with features. also cannot test it personally before give you. (don't have mobo anymore)
    Using it may end with dead mainboard (BIOS chip re-flash will be required, if somethink goes wrong)

  • When I try to log on to my ichat I get the error message "An undefined AIM socket error has occurred.". How do I resolve this?

    The error message "An undefined AIM socket error has occurred." comes up when I try and log on to ichat.

    I have the same issue. Does anybody know why this has happened

  • Assign unique id to client of socket server

    HI
    I am in the process of developing a xml socket server application and have hit on a problem. I have managed to create a server that listens for connections and once a request is recieved creates a new client on a seperate thread with the reference being stored in a vector in the server.
    However I want to be able to assign an id to a client when it is created so that I can broadcast messages to specific users.

    my apologies my question was poorly stated..
    When i meant unique i mean that they will have already been prdefined i.e for example the following users
    Name David
    UserId *(Unique) 0138868
    Name sarah
    UserId *(Unique) 4138868
    Name rob
    UserId *(Unique) 7138868
    what i want to be able to is when the users connect they can be refeneced by their Userid so that if rob wants to say something to sarah without david knowing. The problem I have is that I do not know how to provide the userid to the server such that the server can create a new client thread with a specified id.
    Hope that makes sense ;>

  • Data written to socket getting lost?  or perhaps out of order?

    I'm trying to fix a bug in Flashmog. The bug is described in more detail here.
    Basically what is happening is that my Flash client claims that it is calling functions that don't arrive at the server -- or they arrive, but the socket data is out of order and therefore is garbled.  I've stared at the source code for hours and tried a lot of trial-and-error type stuff and added trace statements to see if I can find the problem and I'm not having any luck.
    In particular, there's class I have called RPCSocket that extends the AS3 Socket class so I can serialize data structures before sending them across a socket.  At one point, this RPCSocket class calls super.writeBytes and super.Flush.  It is the point at which I send all data out of my client. The data is binary data in AMF3 format.
              public function executeRPC(serviceName:String, methodName:String, methodParams:Array):void {
                   if (!this.connected) {
                        log.write('RPCSocket.executeRPC failed. ' + methodName + ' attempted on service ' + serviceName + ' while not connected', Log.HIGH);
                        throw new Error('RPCSocket.executeRPC failed. ' + methodName + ' attempted on service ' + serviceName + ' while not connected.');
                        return;
                   var rpc:Array = new Array();
                   rpc[0] = serviceName;
                   rpc[1] = methodName;
                   rpc[2] = methodParams;
                   var serializedRPC:ByteArray = serialize(rpc);
                   if (!serializedRPC) {
                        log.write('RPCSocket.executeRPC failed.  Serialization failed for method ' + methodName + ' on service ' + serviceName, Log.HIGH);
                        dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, 'RPCSocket.executeRPC failed.  Serialization failed for method ' + methodName + ' on service ' + serviceName));
                   super.writeUnsignedInt(serializedRPC.length);
                   super.writeBytes(serializedRPC);
                   super.flush();
              } // executeRPC
    Can someone recommend a way for me to store without corruption, conversion, or filtering or translation of any kind *all* of the information sent across this socket? I'd like to write it to a file.  I'm guessing that keep a global ByteArray var and storing the info there might work, but I'm wondering how I might get the contents of that ByteArray into a file so I can inspect it.
    Also, I'm wondering if I might be able to inspect what flash actually sends out on the socket?  I have a sneaking suspicion that data I supply to super.writeBytes may be sent out of order or may not actually get sent across the socket.  This bug I'm talking about only seems to happen under high-stress situations when I'm sending dozens of messages per second across this one socket.

    oops...forgot link to bug description: http://flashmog.net/community/viewtopic.php?f=5&t=549

  • Socket connect slow in JDK 1.5?

    We recently began testing our Java Swing application with JDK 1.5, and we noticed that socket.connect()
    calls are taking several seconds to return, when before in 1.4 the calls returned immediately.
    Here is some sample code:
    Socket sock = new Socket();
    InetSocketAddress sockAddr = new InetSocketAddress(inAddress, portNum);
    sock.connect(sockAddr, 2000);
    What could be wrong? I've debugged the code and verified inAddress is an IP address,
    not a hostname.
    -Eric

    Here is the list of enhancements in JDK1.5.
    http://java.sun.com/j2se/1.5.0/docs/guide/net/enhancements-1.5.0.html
    I wonder if any of them are having some effect in the slow connection.
    There are some network properties that you can tweak with. Did you try them?
    Here is the list
    http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html

  • Iphone 4 headphone socket not working headphones won't go all the way in

    My iphone 4 headphone socket not working, the headphones won't go all the way in? any help, ideas?

    I bough a new ipad two a few feels ago and still haven't managed to used any headphones with it.
    It's very annoying as I'm currently in hospital and will be for a few more weeks and this being the reason I bought it!! Now I have to have it on very low volume and not use it in the evening  

  • IPhone 4 ear speaker not working after 2 restores and cleaning the headphone socket.

    Hi,
    I know this problem is not uncommon, but here goes...
    I have an iPhone 4 which was running iOS 5.1.1 a few days ago when the ear speaker stopped working.  I cant hear the other person when I make or recieve a call, but nothing else is wrong with the phone.  It is 18 months old.
    I've searched the discussions and seen some of the suggestions.  I tried cleaning out the headphone socket, with no luck.  I then tried a full restore and update to iOS 6.  This appeared to have worked.  I tried 2 calls and I could hear the other person.  I then left the phone alone for a couple of hours and when I tried it again, it had stopped working again.
    I have since done another full restore but the speaker is still not working at all.  The fact that it worked after the first restore suggests it's something simple or software related but I have no idea what else to try other than getting it repaired in a shop.  The problem is I am in Japan where my network (Softbank) and an independent repair shop have both quoted me the equivalent of $176 / £110 to fix it.
    Does anyone know anything else I can try before I give in and end up shelling out this ridiculous cost for something that is probably a 20 minute fix?
    Any help would be appreciated.
    Thanks

    I have the exact same problem with my ear speaker after my IOS 6 upgrade. My speakers work, bluetooth works, the earphones work, but the ear speaker doesn’t work. I noticed this IMMEDIATELY after the upgrade was completed. I also have the following problems:
    -Very slow call connect time. 30 - 45 seconds just to connect is typical. Signal strength is 5 bars (ATT)
    -Problems attaching to known networks
    -Very slow internet browsing with many timeouts on both the ATT 3G service and known Wi-Fi networks.
    - My camera was missing after the IOS 6 upgrade. I restored that from Restrictions inside of the Settings App
    - Music was so screwed up it was easier to just restore it
    I went to the Apple store hoping to get some support. Between my wife, my son, and myself we have purchased 4 iPhones and an iPad over the last few years with plans to purchase another iPad in a month or so. So it’s not like I' not familiar with Apple Technology and their typical level of support.
    The individual who waited on me was rude and condescending. He insisted that all of the problems were hardware related or ATT’s fault, or my fault. He further asserted that IOS 6 had NOTHING to do with any of the problems. I pointed out that it would be quite a coincidence for my hardware to break, for ATT to have network problems, and for me to suddenly forget how to use an iPhone at the same exact moment that IOS 6 had been installed. He maintained his position and offered to sell me another phone.
    I don’t expect the folks in the store to reprogram the OS. Mistakes happen. I’m going to guess that Apple’s OS programmers are already working on a fix for many of the IOS 6 complaints that are easy to find on Google. Assigning blame to the customer and denying any responsibility is not a model for success or customer service. I’m sure Apple wouldn’t accept that kind of excuse from their component manufacturers and don’t think it is how they should deal with their customers. Further, Apple wants to own the device. They want to control the apps, the OS, battery, the delivery channel. I’m good with that so long as when there is a problem, they own that as well.
    And BTW… I’m not including the maps in my list of issues with IOS 6 because I kind of like the new maps and am willing to give Apple the benefit of the doubt. I believe that their map service will get a lot better in a hurry.

Maybe you are looking for

  • Runtime error r6034  WIN7

    wont let me install new version  keeps saying runtime error r6034?

  • How do I search a word document stored in a BLOB using PHP?

    I have been successful at saving files in a blob field using oracle. I need to search through the word document, how can I do it using PHP? Please help!

  • An other great website!

    Just found a great new site talking exclusively about Ap. www.aperture.fr I guess we have to learn french or use, as Matthew London wrote in an oher thread (thank you) Google translate. I just tried it and the result is quite amazing! Try by yourself

  • Does anyone know when the next upadate will be?

    does anyone know when the next upadate will be?

  • Photosmart printer not printing straight

    I have recently purchased a HP Photosmart 5515 e All-in-One printer (model no. B111h). I managed to set it up with no problems, however, when I try to print out documents I notice the images are not straight - they all seem to be skewed slightly. It