How can C socket talk to Java Socket?

Hello, all
I am writing a gateway program (written in Java) that accepts request from clients (written in C)
My problem is that "Java end" cannot receive an EOF from "C end", thus it is always waiting for it.....
C End
error = 0;
while (error < strlen(request))
         error += write(fd, request, strlen(request));
         if (error < 0)
                 perror("write");
                 return -1;
} /* write */Java End
int c;
while ((c = input.read()) != -1)
         System.out.printf("%c", (char)c);
         request.append((char)c);
System.out.println(request);Could anybody tell me solve this problem?
Thanks!!

The receiver will get an EOF after the sender closes the socket. (Or half closes it; see the shutdown() system call.)
If you want to keep the connection open, you need to use some other end-of-request terminator. Such as \n if the request never has embedded newlines.
Btw, the "while(error < ...)" loop in the sender isn't right. It will make more sense if you add "request += error;" to the loop.

Similar Messages

  • Help--How can I open only one java program at one time?

    How can I open only one java program(same program) in Windows at one time?

    In Java 1.5, you can use the JVM's own monitoring APIs to examine what other JVMs are running on the system, and what applications they're running.
    It's general and powerful, but complex. The socket/file/whatever approach is cleaner, and probably more suited to your usage.
    Don't bother trying to use the Windows task manager for this sort of thing. You have to write messy native code, and it isn't reliable after all that anyway.

  • How can I find out the java version Oracle has ?

    How can I find out the java version Oracle has built in?
    I've tried with ..
    SELECT comp_id, comp_name, version
    FROM dba_registry ;
    But I get.."table doesn't not exist".
    Thenks in advance!

    Pl post details of OS and database versions. Pl see this MOS Doc
    What Version of Java is Compatible With The Database JVM? [ID 438294.1]     
    and these Oracle docs
    11gR2 - http://docs.oracle.com/cd/E11882_01/appdev.112/e25518/adfns_environments.htm#ADFNS654
    11gR1 - http://docs.oracle.com/cd/B28359_01/java.111/b31225/whatsnew.htm
    HTH
    Srini

  • How can I actually talk to customer service?

    How can I actually talk to customer service?

    If you are having problems with Adobe Reader, why not just talk to us? Faster, easier and cheaper.

  • ... how can i use 'enter' in java (text) -.-

    Hi all,
    first the simple version;
    How can i use 'enter' in java. Like turn HELLO into
    H
    E
    L
    L
    O
    The not so simpler version IF needed;
    I have the following piece of code;'
    if (line.startsWith("Monday")) {
         String subjectsMonday = " math and philosophy";
         Calendar c = Calendar.getInstance();
              System.out.format("School begins at" +" 08:10", c, c, c);
              System.out.format(" school ends at " +" 15:55", c, c, c);
         System.out.println("We have the following subjects;" + subjectsMonday);the thing is ... i want the text "we have the following subject; math and philosophy" to start at a new line.
    HOW am i supposed to do that.

    %n may work for you:
            String subjectsMonday = " math and philosophy";
            Calendar c = Calendar.getInstance();
            System.out.format("School begins at" + " 08:10%n", c, c, c);
            System.out.format(" school ends at " + " 15:55", c, c, c);
            System.out.println("We have the following subjects;" + subjectsMonday);

  • How can i use talking caller id without jailbreak and those wacky apps

    how can i use talking caller id without jailbreak and those wacky apps

    Talking caller ID is not a feature of the iPhone. If by "wacky apps" you mean the ones that make custom ring tones for each contact from their name, that's your best bet.

  • How can i create messenger with java tv API on STB

    deal all.
    how can i create messenger with java tv API on STB.
    how can Xlets communicate each other?
    how?
    i am interested in xlet communications with java tv.
    is it impossible or not?
    help all..

    You can create a messenger-style application using JavaTV fairly easily. JavaTV supports standard java.net, and so any IP-based connection is pretty easy to do. The hard part of the application will be text input, but people have been using cellphone keypads to send SMS messages for long enough that they're familiar with doing this. This doesn't work well for long messages, where you really need a decent keyboard, but for short SMS-type messages it's acceptable.
    The biggest problem that you need to work around is the return channel. Many receivers only have a dial-up connection, ties up the phone line and potentially costs people money if they don't get free local calls. Always-on return channels (e.g. ADSL or cable modem) are still pretty uncommon, so it's something that you nee to think about. Of course, if you do have an always-on connection then this problem just goes away.
    This is really one of those cases that's technically do-able, but the infrastructure may not be there to give users a good experience.
    Steve.

  • How can I change the Jframe Java help Icon

    How can I change then Jframe Java help Icon?.
    I am using then HelpSet class and HelpBroker.
    I want to change the java help icon
    Any Idea? thanks. ...

    It can be done, but it's ugly...
    Add in a listener to your topmost JFrame to sense when the focus is lost, since this happens when a help window comes up. When the focus leaves the main window, check all the windows that are up to see if one is a help window. If so, this will give you a reference to the help window and you can drill down to change what you want.
    Here's an example that changes the icon and removes the borders from the javahelp buttons.
    WindowListener wndCloser = new WindowAdapter() {
              //A necessarily roundabout method to affect
              //look and feel aspects of the javahelp viewer.
              //(there is no way to get at these components directly.)
              //When the main frame loses focus, it may be because
              //the help viewer was brought up. Look through all
              //the current frames to see if one is a help viewer.
              //If it is, change the look of the help viewer
              //to what we want.
              Frame m_helpFrame = null;
              public void windowDeactivated(WindowEvent e) {
              if (m_helpFrame != null)
                   return;
              Frame[] frames = getFrames();
              for (int k = 0; k < frames.length; k++) {
                   if (!(frames[k] instanceof JFrame))
                   continue;
                   JFrame jf = (JFrame)frames[k];
                   if (jf.getContentPane().getComponentCount()==0)
                   continue;
                   Component c = jf.getContentPane().
                   getComponent(0);
                   if (c == null || !(c instanceof JHelp))
                   continue;
                   m_helpFrame = jf;
                   //now that we know the Frame, we can change the title icon
                   final Image image2 = <your icon here>
                   m_helpFrame.setIconImage(image2);
                   JHelp jh = (JHelp)c;
                   for (int s=0; s<jh.getComponentCount(); s++) {
                   c = jh.getComponent(s);
                   if (c == null || !(c instanceof JToolBar))
                        continue;
                   JToolBar jtb = (JToolBar)c;
                   //now that we've accessed the toolbar, we can
                   //modify the look of the buttons.
                   for(int i=0; i<jtb.getComponentCount(); i++) {
                        Component comp = jtb.getComponentAtIndex(i);
                        if(comp instanceof JButton) {
                        JButton button = (JButton)comp;
                        button.setBorder(null);

  • How can i validate items in java

    hi....
    how can i validate items in java....so that user can not type in characters
    in the place of number????
    please help?!?

    Hope u know getText() method returns string
    i.e text1.getText() returns string.
    U need to convert the string to integer with integer class. Go
    to the documentation to search for it.
    Then attach a conditional statement stating if not numeric
    , then not valid. if u have little knowledge of java, u will understand it.
    Otherwise, wait till tomorrow bcos I'm late for xmas carol.

  • How can i become Sun Certified Java Programmer?

    Dearl All,
    Can anyone tell me how can i become Sun Certified Java Programmer?
    Thanks in Advance..
    thanks & Regards,
    Mark Spenser
    [web design los angeles|http://www.plaveb.com]

    No link sigs in here please.
    See this link for all information needed:
    [http://www.sun.com/training/certification/]

  • I've 2 versions of Java installed! How can I uninstall Apple's Java 6?

    This is where I'm at
    * Updated from Snow Leopard to Mountain Lion
    * Installed Oracle Java 7 update 7 dmg
    * Misread an out of date OS X Daily blog where I got this Terminal command java -version. It lead me to think Java 7 wasn't installed
    * Installed Apple Java 6 via the Java Prefs app. Thought this would somehow lead to a Java 7 upgrade along the way.
    * Realised that Oracle Java 7 was installed fine the first time, but java -version doesn't work with it !!
    * Now I have 2 versions of Java installed!
    * I reinstalled Java 7 (this time using 7 update 10) hoping it would remove Apple's Java 6 but it didn't remove it.
    *For some reason too the old Java Prefs app has been automatically deleted too, so I can't switch Apple Java 6 off.
    Confirmation that I have 2 Java versions installed
    If I type the terminal command java -version it says I have Apple Java 6 installed.
    If I open LibreOffice/Preferences/Java it says I have Apple Java 6 installed.
    If I open Play Station 3 Media Server it says it's using Apple Java 6.
    If I open some other Java .jar apps like JOSM it says it's using Oracle Java 7
    Oracle has a FAQ that recomnds deleteing old versions of Java, but very helpfully only gives instructions for Windows.
    How can I uninstall Apple's Java 6?
    Thanks

    Reinstall the OS …  meaning reinstall OS X?!   Is that not a bit over the top?
    >"BTW, do note that all you're really doing is changing the Java Runtime Environment component and not Java."
    At this stage I don't have a clue what I doing !!
    In the past week and a half I have had a belly-full of Java name permutations. What kind of sick, twisted mind came up with Java naming scheme: Just take the word Java and append two or three letters to it using every permutation possible, throw in a few numbers for good measure, and then when discussing it just use the generic term Java… that'll really catch 'em out.
    …Java SE, Jave RE, Java JDK,Java Platform, Apple Java 6, Oracle Java 7, Java 1.6.0_27, Java 1.7.0_10, Java 6, Java 7, ….. not to mention Java FX, Java DB, Java ME, Java EE, Java DST…

  • How can i vusualize the application Java in my system ? i have actually problems to install my bank's protection module -

    How can i vusualize the application Java in my system ? i have actually problems to install my bank's protection module … My computer is an Imac and the Operation System is OS X Mountain Lion 10.8.2 ... PLEASE HELP ... THANKS !!!

    Thanks about your advise but i can not change my bank accout ... this protection module will only works if i have the java installed in my imac ... I just bought the OS X Mountain Lion (10.8.2) new version and i can not see WHERE IS THIS JAVA ??? When i open my "system preferences / others / ... there is nothing  . My bank told  me that without this JAVA i Will not have my protection module. Can you help me  to find it in my Imac ???

  • How can I uninstall this latest java upgrade?

    I just installed a java upgrade called "build 1.6.0_05-b13 and now I cannot get Microsoft Front Page 2003 to work. I have to use MS Front Page to maintain my website. How can I uninstall this latest java upgrade so it will go back to using my previous version of java?

    I believe you may have posted your question to the wrong forum. This forum is for the JavaHelp system, which is used for developing online Help for applications, not for general help on Java.

  • Adobe is asking for Java SE 6 runtime. How can I use Oracle's Java 7 instead?

    Platform: Mac OS X, version 10.9.2 (the latest available as of May 11, 2014)
    When trying to open my old Adobe Illustrator, as part of Creative Suite CS4, I get the following error message:
    To open "Adobe Illustrator CS4," you need a Java SE 6 runtime. Would you like to install one now?
    I have the latest Oracle Java 7 (Version 7 Update 55) installed and I don't want the historic Apple Java 6. How can I configure Adobe software to use the already installed Java 7?
    Best, regards
    Tom

    despite this being for a different os, read (especially the end paragraphs) Install Java (JRE) | Mac OS 10.7 Lion

  • How can I create a scheduled java application/task?

    Hi,
    Being a complete newbie to the Java language, I hope I am forgiven if the above is blindingly obvious.
    I have a java application which I have developed that when run from the command prompt (java xyz) selects a bunch of records from my database, then creates a text file with the results. Pretty simple stuff.
    My question is, how can I automate this process? I would like it to run every night at midnight. Will I have to create a batch file? If so, how? Help!!
    Any advice would be much appreciated :)
    Thanks, Chris

    Scheduling a task is a very Operating System dependent operation. It does not exist in some OS's without some kind of addin. Things of this sort are usually not done exclusively in Java, unless you want to have your application running all the time and simply perform some operation at a specific time (see Timer). Otherwise look on google.com for 'scheduler' and 'windows 98' for example.

Maybe you are looking for

  • Free booster offer

    has anyone managed to get a free boster with the sk go sign up offer that is plastered all over the tv at the moment.I need a booster as the wifi stability is terrible yet paying extra with no guarentee is not something i am willing to do.i set a sky

  • Did Apple remove support for DNG files generated out of Capture One?

    I use Capture One to convert my Leica Dlux-4 RAW files into DNG format and then use Aperture2.1.4 as my photo processing tool. After I ran the latest OS update - Aperture gives a "Unsupported file format" message for all the DNG files. Is it possible

  • CS5 extended suddenly not working

    Message is Activation limit reached for Adobe PS CS5 extended.  I have been using this for probably 2 years now and suddenly this happens.  Says this is the 3rd computer but this is the same computer I have been using it for.    So what shall I do? 

  • My network goes off and does not come back unless I switch off and switch on

    I have a vodafone connection. Whenever I go underground while traveling in train, my network goes off and but does not come back unless I switch off and switch on the phone... any suggestions???

  • Energy Saver optimization settings missing in 10.5.8

    I seem to have lost my optimization settings in the Energy Saver preference pane. I'm using a unibody MBP 13" running on 10.5.8, with Energy Saver version 4.4.3.. Does anybody else have this problem, and/or has anybody found a solution? Appreciate an