Sending data to xport doesn't work correctly

Dear programmers,
For my thesis I have to send data from a computer to a microcontroller trough TCP/IP. So I've written a program in java dat sends the data, but it goes wrong. This is my code:
import java.io.*;
import java.net.*;
public class Connection {
     private Socket socket = null;
    private PrintWriter output = null;
    private BufferedReader input = null;
    private BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));;
     public boolean createConnection(String ip, int port) {
        boolean connect = false;
        try {
            socket = new Socket(ip, port);                                                            // Maakt socket aan naar gegeven poort en ip
            output = new PrintWriter(socket.getOutputStream(), true);                         // Output naar de server
            input = new BufferedReader(new InputStreamReader(socket.getInputStream()));     // Ontvangen gegevens van server
            connect = true;
        } catch (UnknownHostException e) {
            connect = false;
             System.err.println("Kan geen verbinding maken naar ip-adres: " + ip);
            System.exit(1);
        } catch (IOException e) {
             connect = false;
            System.err.println("Kan geen input/output verkrijgen van ip-adres: " + ip);
            System.exit(1);
        return connect;
     public boolean sendMessage(String message) {          
          output.println(message);
          output.println("\r\n")
          return true;
     public String receiveMessage() {
          String message = null;
          try {
               message = input.readLine();
          } catch (IOException e) {
               e.printStackTrace();
          if(message.equalsIgnoreCase("HTTP/1.1 0 ERROR")) {
               message = "#ERROR#";
          return message;
     public boolean getStatus() {
          if(socket.isConnected()) {
               return true;
          else {
               return false;
     public void closeConnection() {
          try {
               output.close();
               input.close();
               stdIn.close();
               socket.close();
          } catch (IOException e) {
               e.printStackTrace();
}The first time I send something it goes correctly, but when I try to send the second data it goes wrong.
So as example I send 100 times the number 512 to the xport.
1st time: 512
2nd time: 5
3th time: 52
4th time: 5125
So only the first time it sends the data correctly. It's my program and not the xport because trough hyperterminal the data is sended correctly. I hope you guys can help me.

Okay, thanks for your reaction. Now I changed my Connection.java code into:
import java.io.*;
import java.net.*;
public class Connection {
     private Socket socket = null; 
    private BufferedOutputStream ostream = null;
    private BufferedInputStream istream = null;
     public boolean createConnection(String ip, int port) {
        boolean connect = false;
        try {
            socket = new Socket(ip, port);
            ostream = new BufferedOutputStream(socket.getOutputStream());
            istream = new BufferedInputStream(socket.getInputStream());
            connect = true;
        } catch (UnknownHostException e) {
            connect = false;
             System.err.println("Kan geen verbinding maken naar ip-adres: " + ip);
            System.exit(1);
        } catch (IOException e) {
             connect = false;
            System.err.println("Kan geen input/output verkrijgen van ip-adres: " + ip);
            System.exit(1);
        return connect;
     public boolean sendMessage(String message) {
          byte[] buffer = new byte[10];
          try {
               buffer = message.getBytes();
               ostream.write(buffer, 0, message.length());
               ostream.flush();
          catch(Exception e) {
               e.printStackTrace();
          return true;
     public String receiveMessage() {
          String message = null;
          byte[] readBuffer = new byte[40];
          try {
               int message_int = istream.read(readBuffer, 0, 40);
             message = new String(readBuffer, 0, message_int);
          } catch (IOException e) {
               e.printStackTrace();
          if(message.equalsIgnoreCase("HTTP/1.1 0 ERROR")) {
               message = "#ERROR#";
          return message;
     public boolean getStatus() {
          if(socket.isConnected()) {
               return true;
          else {
               return false;
     public void closeConnection() {
          try {
               ostream.close();
               istream.close();
               socket.close();
          } catch (IOException e) {
               e.printStackTrace();
}Do you think this was the problem? Maybe it was. Let's hope so. I will let you know something when I tested it tomorrow in school.

Similar Messages

  • After upgrade my iphone 4 to IOS6, sound doesn't work correctly

    After upgrade my iphone 4 to IOS6, sound doesn't work correctly.
    During a phone call, there is no sound. But if I turn on the speaker, there is sound. itune works fine since it's on the speaker.

    Dear All
    i have done the same activity ( buy a new iphone 4 -> upgrade to ios5 - > configure email) with success-
    than when i start to move the contacts from old mobile to iphone (using the microsim) i receive the same crash
    in disgnosis e use i saw 2 dump with this title 'latestCrash-Preferences.plist and LatestCrash.plist. in each file the date is the same and i read:
    Exception Tyle: EXC_CRASH (SIGABRT)
    Exception code: 0x00000000, 0x00000000
    Chrashed Thread: 6
    in thread 6: name: Dispatch queue:
    com.apple.addressBookUI.ContactsSettingPlugin
    and thaan a lot of data.
    Have you any idea?
    thank in advance
    Fabio

  • Translation from CS5 to Cloud doesn't  work correct, navi and linked images are broken.

    Translation from CS5 to Cloud doesn't  work correct, <navi> and linked images are broken.
    The data of CS5 was created at another PC. I installed Cloud version into two different PC. One has had the site data since dreamweaver CS5 and it works correct in Cloud version. Another PC got the site data from remote server and it doesn't work correct. <navi> and linked image are broken.

    Another PC got the site data from remote server and it doesn't work correct. <navi> and linked image are broken.
    This implies your site is not properly defined in DW.  Go to Site > Manage Sites.
    Or simply go to your other installation of DW and export the site definition file from Manage Sites.
    Save it to a flash stick or other removable drive.  Then import the STE file into your 2nd installation of  DW.
    Nancy O.

  • [svn] 4028: Bug: Draining of buffered messages doesn' t work correctly with long-polling.

    Revision: 4028
    Author: [email protected]
    Date: 2008-11-06 09:04:26 -0800 (Thu, 06 Nov 2008)
    Log Message:
    Bug: Draining of buffered messages doesn't work correctly with long-polling.
    QA: Yes - please make sure both nio and regular long-polling channels work with throttling.
    Doc: No
    Checkintests: Pass.
    Details: Made sure that buffered messages are drained properly with all polling channels (polling, long-polling, and nio-long-polling).
    Modified Paths:
    blazeds/trunk/modules/core/src/flex/messaging/client/FlexClient.java

    Sounds like you've probably already looked but the CUPS article in the wiki led me through setting up a printer without any problems.  http://wiki.archlinux.org/index.php/CUPS
    The first section describes how to troubleshoot CUPS and printing problems.
    I've also found a few other posts and links that may help.
    http://hplipopensource.com/hplip-web/mo … eries.html
    http://ubuntuforums.org/showthread.php?t=419163
    Hope this helps!

  • I created an apple ID account to my Iphone, but the system doesn´t send the verification link to my email adress. I tried many times with the buton "send verification email" but doesn´t work.

    I created an apple ID account to my Iphone, but the system doesn´t send the verification link to my email adress. I tried many times with the buton "send verification email" but doesn´t work. My mailbox doesn´t receive any mail.
    My account work correctly.
    please I need help.
    Thank you.

    It's a really bad idea to post your email addresess - it's an invitation to spam - and I've asked the Hosts to remove them.
    This is a user-to-user forum and no-one on here can take any direct action. If your Yahoo address is not working that's something you would need to take up with Yahoo - have you checked it by sending yourself an email to it?
    Otherwise you will need to contact Support: go to https://expresslane.apple.com/ and click on 'iTunes' in the center column and then 'iTunes Store' in the right-hand column and proceed from there.

  • Format date with "yyww" doesn't work

    Format a date to the format "yyww" doesn't work correctly for the first week of some years. It seams to be weeks that start in December that doesn't work.
    DateFormat df = new SimpleDateFormat("yyww", Locale.FRANCE);
    String in = "0801";
    // Gives: Mon Dec 31 00:00:00 CET 2007
    Date d = (Date) df.parseObject(in);
    System.out.println(d);
    // !? Gives: 0701
    String out = df.format(d);
    System.out.println(out);Any help appreciated!

    You're right. ISO 8601 Whichever year contains Thursday determines which year the week belongs to.
    The U.S. locale plays by different rules though. At least according to GergorianCalendar, if even one day falls in the new year, it is week 01. This little program displays this:
    import java.io.UnsupportedEncodingException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import java.util.Locale;
    import java.util.TimeZone;
    import java.text.MessageFormat;
    import javax.swing.JOptionPane;
    public class CalendarTest {
         public static void main(String args[]) throws UnsupportedEncodingException {
              try {
                  if (args.length != 0) {
                       doYear(new Integer(args[0]).intValue());
                       return;
              } catch (NumberFormatException nfe) {
              doYear(2005);
              doYear(1998);
              doYear(1993);
          * Method main
          * @param args
         public static void doYear(int year) throws UnsupportedEncodingException {
              System.out.println();
              System.out.println(year);
              GregorianCalendar a = new GregorianCalendar(TimeZone.getTimeZone("GMT-8"), Locale.US);
              GregorianCalendar b = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"), Locale.GERMANY);
              a.set(Calendar.YEAR, year);
              a.set(Calendar.MONTH, Calendar.JANUARY);
              a.set(Calendar.DAY_OF_MONTH, 1);
              b.set(Calendar.YEAR, year);
              b.set(Calendar.MONTH, Calendar.JANUARY);
              b.set(Calendar.DAY_OF_MONTH, 1);
              while (a.get(Calendar.DAY_OF_WEEK) != a.getFirstDayOfWeek()) {
                   a.add(Calendar.DAY_OF_MONTH, -1);
              while (b.get(Calendar.DAY_OF_WEEK) != b.getFirstDayOfWeek()) {
                   b.add(Calendar.DAY_OF_MONTH, -1);
              do {
                   System.out.println("US:  " + a.getTime() + " " + a.get(Calendar.WEEK_OF_YEAR));
                   a.add(Calendar.DAY_OF_MONTH, 1);
              } while (a.get(Calendar.DAY_OF_MONTH) != 8);
              System.out.println();
              do {
                   System.out.println("DE:  " + b.getTime() + " " + b.get(Calendar.WEEK_OF_YEAR));
                   b.add(Calendar.DAY_OF_MONTH, 1);
              } while (b.get(Calendar.DAY_OF_MONTH) != 8);
    }

  • Game Center doesn't work correctly

    Game Center on iPod Touch 2nd Gen doesn't work correctly under iOS 4.2.1
    It shows wrong language (Englist but not my native language. My region setting is right and the system language right too.)
    Besides, the "Games" page only has a button "Find Game Center Games", while it should show my Game Center Games.
    The Friends page shows all my friends. But when I press a friend the sub page doesn't show the game my friend and I have in common.
    I've restored my device several times, but it didn't help.
    How to solve it?

    I've had exactly the same problem on my 2nd gen since early May when it just stopped working out of the blue.
    There are a few threads here on the subject. I believe that every 2nd gen is affected as I've yet to hear a 2nd gen owner say that theirs works.
    Other than waiting for Apple to fix it I don't think there is a solution.

  • AddChild doesn't work correctly in 11.9

    comparing the two releases listed below, somehow my Flash program doesn't work correctly on the latest version anymore, nothing was changed in my program but after upgrading to the latest Flash Player, it doesn't work properly anymore, specifically, the items I add through the addChild method doesn't appear properly, was there any changes in between these versions that could have affected the addChild behavior? I'm testing with Windows  7 IE debug version and I see no script errors
    Released 10/8/2013) Flash Player 11.9.900.117 (156.2 MB)
    (Released 9/24/2013) Flash Player 11.8.800.175 (Win IE only) (50 MB)

    Could you please open a new bug report on this over at bugbase.adobe.com?  When adding the bug, please include sample code, test url or a test swf so we can quickly test this out internally.  If you'd like to keep this private, feel free to email the attachment to me directly ([email protected]). 
    Once added, please post back with the bug URL and I'll investigate internally.
     

  • IPhoto doesn`t work correctly with german "umlaut" (ä,ö,ü) in keywords

    iPhoto doesn`t work correctly with german "umlaut" (ä,ö,ü) in keywords. They get to ä̈,ö̈, ü̈ when I write the keyword a second time. Can anybody tell me why. Thank you. Heinz

    It apparently does not like non-standard English characters - use A-Z and 0-9 adn you should be OK
    report to Apple - iPhoto menu ==> provide iPhoto feedback
    LN

  • ITunes 10.4 full screen with Win7-64bit doesn't work correctly.

    iTunes 10.4 full screen with Win7-64 doesn't work correctly. I have the Windows taskbar on the left side of my screen. Maximized iTunes is panned to the left.

    Same issue here. When the Windows taskbar is position on the top of the screen and then the iTunes windows is maximised, it's position is as if the Windows taskbar is at the bottom of the screen so the top of the iTunes window sits under the taskbar.
    For those wanting a workaround, hold shift and right click the iTunes icon in the taskbar/quick launch bar and click restore, at least then you can adjust it to be full screen manually.
    System:
    Windows 7 Ultimate x64
    iTunes 10.4
    ATI 5750 video card

  • How can I avoid duplicates on contacts and how do I get contacts created on iPhone/ipad synchronized on my mac? so far it doesn't work correctly, just sometimes. same for icalendar

    how can I avoid duplicates on contacts and how do I get contacts created on iPhone/ipad synchronized on my mac? so far it doesn't work correctly, just sometimes. same for icalendar

    On your Mac, for duplicates, switching Contacts off then back on in System Preferences > iCloud may prevent duplicates.
    On the iPhone / iPad tap Settings > iCloud. Make sure Contacts and Calendars are swtiched on.
    Try restarting your Mac and your iOS devices when items won't sync as they should.
    To restart an iOS device:  Hold the On/Off Sleep/Wake button down until the red slider appears. Slide your finger across the slider to turn off iPhone. To turn iPhone back on, press and hold the On/Off Sleep/Wake button until the Apple logo appears.

  • ASR1002 - For DNS it seems that NAT doesn't work correctly

    Hi Folks,
    For DNS it seems that NAT doesn't work correctly
    The ASR 1002 works as a NAT-Router. But for DNS it seems that NAT doesn't work correctly.
    All DNS packets with a frame size greater than 512byte are not processed (they donїt arrive at the DNS Server), but we can't verify if they are dropped or just not processed.

    Sorry guys its everytime*

  • Bought a new Mac, migrated data, now CS4 doesn't work. Why?

    I bought a new Mac, had the Apple guys migrate my data and apps to it. Now CS4 doesn't work.
    I researched a bit and found that I SHOULD have deactivated and uninstalled CS4 from my old Mac. I've now done that.
    But do I have to uninstall CS4 files from my new Mac now--and reinstall? Will that work?

    Hi,
    I have a question related to one you answered above: "bought a new Mac, migrated data, now CS4 doesn't work."
    My situation is a little different. I am hoping you can help me with it. I hope I am not violating any protocols by asking you specifically?  A year ago I reinstalled my Mac's operating system. My CS4 is on my computer under "Previous System." I am unable to open it from there and I do not want to attempt migrating it for reasons noted above. I did try to reinstall it as you suggested to hbrady67 by dowloading from CS4 products with my serial number but I got this message: "Upgrade Check  We looked in the default location for qualifying products installed on the machine, but none were found. You may verify upgrade eligibility now by completing the fields to the right. 1) Select a product you already own. 2) Enter a serial number for this product.  CS4 wasn't in the list of selections. The protocol suggested won't work for me since I am not doing an upgrade but trying to reinstall what I already have. Can you direct me on where to go/what to do?  Thank you very much.      Bergi.
    I found the solution to this problem. I was able to download the trial version of what I have and enter the serial number from there. However, it still asked for a serial number from previous software: "your setup is for an upgrade version of Adobe Creative Suite 4." (I entered the serial number that I have for CS2. And it was accepted.  Thank you.  Bergi

  • Macintosh: Adobe Muse; Formular Widget: Send button in Firefox doesn't work (Mac, PC). Works in Safari (Mac) IE (PC). What's happening?

    Macintosh: Adobe Muse; Formular Widget: Send button in Firefox doesn't work (Mac, PC). Works in Safari (Mac) IE (PC). What's happening?
    URL Test: News
    Greetings from cold Switzerland....
    Beat

    I believe you have resolved this , as I tested on my end and the submit button worked fine.
    Thanks,
    Sanjit

  • Link on my website doesn't work correctly on my iMac. It works correctly on Safari, and both browsers on my laptop.

    Link on my website doesn't work correctly on my iMac. It works okay when using Safari. It also works correctly on my laptop using either browser.

    We worked out my problem. My solution turned out to be: Firefox Preferences/Applications. Scroll down until you find "Portable Document Format (application)", click on it and use the dropdown menu to the right and changed "Save file" to "Use Adobe Acrobat Pro (default). I had trouble at first finding if the listing was under Adobe, Acrobat, or what so I used the search feature and found it immediately.
    Hope this helps.

Maybe you are looking for