Fedora Linux Support Community & Resources Center
  #1  
Old 13th May 2011, 02:48 PM
newbie14 Offline
Registered User
 
Join Date: Feb 2010
Posts: 104
windows_xp_2003ie
Stuck with readline and acknowledgement processing

Dear All,
Below is my java codes. Currently the codes gets data from gps devices. The problem now if you notice is that I have to send twice the acknowledgement message that is w.write("$PA\n"); w.flush(); once in line 56 and 57 and once more in 85 and 86 then only I will receive all the 5 strings. Currently my method of receving is the one I have commented out that is from 62 to 128. I notice that if I dont know send the second acknowledgement I only receive the single string but it suppose to be 5 strings. So I am trying to revert to readline method at line 58 but unfortunately it always wait for \n rather than null. Any help.


import java.io.*;
import java.net.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.io.IOException;
public class commServer {
public static void main(String[] args) {
try {
final ServerSocket serverSocketConn = new ServerSocket(9000);
while (true)
{
try
{
Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();
}
catch(Exception e)
{
System.out.println("MyError:Socket Accepting has been caught in main loop."+e.toString());
e.printStackTrace(System.out);
}
}
}
catch (Exception e)
{
System.out.println("MyError:Socket Conn has been caught in main loop."+e.toString());
e.printStackTrace(System.out);
//System.exit(0);
}
}
}
class ConnectionHandler implements Runnable {
private Socket receivedSocketConn1;
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy");
DateFormat inDf=new SimpleDateFormat("ddMMyyHHmmss");
DateFormat outDf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ConnectionHandler(Socket receivedSocketConn1) {
this.receivedSocketConn1=receivedSocketConn1;
}
//@Override
public void run() {
BufferedWriter w = null;
BufferedReader r = null;
try {
PrintStream out = System.out;
BufferedWriter fout = null;
w = new BufferedWriter(new OutputStreamWriter(receivedSocketConn1.getOutputSt ream()));
r = new BufferedReader(new InputStreamReader(receivedSocketConn1.getInputStre am()));
int m = 0, count=0;
String line="";
String n="";
w.write("$PA\n");
w.flush();
while ((line = r.readLine()) != null) {
// Print the content on the console
System.out.println (line);
}
/*while ((m=r.read()) != -1)
{
Date dateIn = new Date();
n = n + (char) m;
int i = n.indexOf("GET");
if(i != -1) {
break;
}
if (m==35)
{
String ori = n;
String noCheckSum = n.substring(0,(n.length()-4));
int addExist = n.indexOf("@");
String[] slave = null;
if(addExist!=-1)
{
slave = noCheckSum.split("@");
n = slave[0];
} else
{
n = noCheckSum;
}
String[] result = n.split(",");
w.write("$PA\n");
w.flush();
int count1 = 0;
Date date = Calendar.getInstance().getTime();
String today = formatter.format(date);
String filename= "MyDataFile"+today+".txt";
boolean append = true;
FileWriter fw = null;
try
{
fw = new FileWriter(filename,append);
fw.write(ori+" "+dateFormat.format(dateIn)+"\n");//appends the string to the file
Date dateOut = new Date();
fw.write("$PA"+" "+dateFormat.format(dateOut)+"\n");//appends the string to the file
}
catch (IOException ex)
{
//ex.printStackTrace(new PrintWriter(sWriter));
System.out.println("MyError:IOException has been caught in in the file operation"+ex.toString());
ex.printStackTrace(System.out);
}
finally
{
try
{
if ( fw != null )
{
fw.close();
}
else
{
System.out.println("MyError:fw is null in finally close");
//logger.log(Level.SEVERE, "MyError:fw is null in finally close", "");
}
}
catch(IOException ex){
System.out.println("MyError:IOException has been caught in fw is null in finally close");
ex.printStackTrace(System.out);
}
}
n="";
}
}*/
}
catch (IOException ex)
{
System.out.println("MyError:IOException has been caught in in the main first try");
ex.printStackTrace(System.out);
}
finally
{
try
{
if ( w != null )
{
w.close();
}
else
{
System.out.println("MyError:w is null in finally close");
}
}
catch(IOException ex){
System.out.println("MyError:IOException has been caught in w in finally close");
ex.printStackTrace(System.out);
}
}
}
}
Reply With Quote
Reply

Tags
acknowledgement, processing, readline, stuck

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
readline + binding; still frustratd after 4 yrs trying Bill Case Using Fedora 2 7th March 2010 05:48 AM
[SOLVED] How to use processing.org's Processing-1.0.9 as an Application rjames Installation and Live Media 4 3rd March 2010 09:31 PM
Parallel Processing in PHP alirizwan Programming & Packaging 3 14th September 2005 03:39 PM
readline for php RoadRunner Using Fedora 0 2nd September 2005 02:06 AM


Current GMT-time: 10:34 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat