| Problem communicating with socket application |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- Notifying ClientsHi,
I want my server to notify all the clients connected to it.
Basically the server should send the no. of files (count) in each
directories. I don't want the server to send this to each and every
client individually. This should be done in an efficient way.
Will JMS be used efficiently for this? or Is there any other way
to do this efficiently?
Thanks,
Ganesh
- 2
- How to intercept Ctrl key - eg Ctrl E being pressed on Java console programHello
I am writing console programs and my program waits streaming in text input
from the screen. But I need a way for the user to abort - I thought Ctrl
E - but how can I know when Ctrl E has been pressed.
I am roughly doing this sort of thing:
import java.io.*;
public class blah
{
public static void main(String[] args)
{
// declaration section:
BufferedReader cin = null; // console input
String conline;
try
{
cin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter strings to remove last character");
System.out.println("waiting... Press Ctrl E to end session");
while ((conline = cin.readLine()) != null)
{
// If Ctrl E detected abort - break out - BUT HOW???
System.out.println("processing: " + conline);
int len = conline.length();
String strRemovedot = conline.substring(0,len-1);
System.out.println(strRemovedot);
}
cin.close();
}
catch (IOException e)
{
System.err.println("IOException: " + e);
}
}
}
- 4
- Checbox help!!!I am trying to write a program that calculates the price when the checkboxes
are selected and the calculate button is pressed.
Now I am not sure how to code the part where you click the box and the price
of that item appears. Any suggestions?
Here is what I have now:
import java.awt.*; //Abstract Window Toolkit (AWT) for creating
//painting graphics, interfaces and images
import java.applet.*; //gives the classes for an applet to create and
//communicate in applet context
import java.awt.event.*; //gives classes and interface for different
//types of events from the AWT
import java.text.DecimalFormat; //this class formats decimal numbers
public class PetsApplet extends Applet implements ActionListener
{
//labels declared
Label welcomeLabel = new Label ("Welcome to the Pet Clinic");
Label price = new Label("The total price is $0");
Label current = new Label("The current price is $0");
Label serLabel = new Label("Select the service:");
//string text declared
String currentString = new String();
String priceString = new String();
//checkboxes identified
Checkbox officeBox = new Checkbox("Office Visits $10");
Checkbox vacBox = new Checkbox("Vaccination $25");
Checkbox xrayBox = new Checkbox("X-Rays $40");
Checkbox hosBox = new Checkbox("Hospitalization $100");
Checkbox denBox = new Checkbox("Dentistry $50");
Checkbox labBox = new Checkbox("Laboratory Work $30");
Checkbox heartBox = new Checkbox("Heartworm Prevention $35");
Checkbox boardBox = new Checkbox("Boarding $5");
Checkbox preBox = new Checkbox("Prescription $55");
Button calcButton = new Button ("Calculate");
Label outputLabel = new Label("Click the calculate button for total price");
//price variables of the services declared along with the totalPrice
int totalPrice = 0;
int officeBoxPrice = 10, vacBoxPrice = 25, xrayBoxPrice = 40, hosBoxPrice =
100;
int denBoxPrice = 50, labBoxPrice = 30, heartBoxPrice = 35, boardBoxPrice =
5, preBoxPrice = 55;
public void init()
{
//adds all the components to the applet interface
setBackground (Color.blue);
add(welcomeLabel);
add(serLabel);
add(officeBox);
add(vacBox);
add(xrayBox);
add(hosBox);
add(denBox);
add(labBox);
add(heartBox);
add(boardBox);
add(preBox);
add(current);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
add(price);
}
public void actionPerformed(ActionEvent e)
{
//the current price statement is identified
if (officeBox.getState())
currentString = ("The current price is $"+ Integer.toString
(officeBoxPrice));
if (vacBox.getState())
currentString = ("The current price is $"+ Integer.toString (vacBoxPrice))
;
if (xrayBox.getState())
currentString = ("The current price is $"+ Integer.toString (xrayBoxPrice))
;
if (hosBox.getState())
currentString = ("The current price is $"+ Integer.toString (hosBoxPrice))
;
if (denBox.getState())
currentString = ("The current price is $"+ Integer.toString (denBoxPrice))
;
if (labBox.getState())
currentString = ("The current price is $"+ Integer.toString (labBoxPrice))
;
if (heartBox.getState())
currentString = ("The current price is $"+ Integer.toString (heartBoxPrice)
);
if (boardBox.getState())
currentString = ("The current price is $"+ Integer.toString (boardBoxPrice)
);
if (preBox.getState())
currentString = ("The current price is $"+ Integer.toString (preBoxPrice))
;
//the text is set equal to currentString
current.setText (currentString);
//total price is calculated
totalPrice = 0;
if (officeBox.getState())
totalPrice += officeBoxPrice;
if (vacBox.getState())
totalPrice += vacBoxPrice;
if (xrayBox.getState())
totalPrice += xrayBoxPrice;
if (hosBox.getState())
totalPrice += hosBoxPrice;
if (denBox.getState())
totalPrice += denBoxPrice;
if (labBox.getState())
totalPrice += labBoxPrice;
if (heartBox.getState())
totalPrice += heartBoxPrice;
if (boardBox.getState())
totalPrice += boardBoxPrice;
if (preBox.getState())
totalPrice += preBoxPrice;
//output statement for total price is identified
priceString = ("The total price is $" + Integer.toString (totalPrice));
price.setText (priceString);
//statements to clear the fields after the calculate button is clicked
officeBox.setState(false);
vacBox.setState(false);
xrayBox.setState(false);
hosBox.setState(false);
denBox.setState(false);
labBox.setState(false);
heartBox.setState(false);
boardBox.setState(false);
preBox.setState(false);
}
}
- 7
- Hel me! I'm going mad!!!Excuse me if I'm repetitive but I need help.
I thank Micheal Dunn but his suggestion is too particular and it's too
legates to a specific map of a museum.
I have this problem.
I have a map of a generic museum. Every room has maximum 4 links to other
room. These links have not a cost(the cost is always 1). I must implement a
algorithm to determinate the shortest path from a room to another room.
I have created a Class room, this class have these methods eand these data:
Method:
public int getNumVicini() //this method gives the number of room linked the
the object room in question;
public int getVicino(int v)//this method returns the 1st or the2nd or the
3rd or the 4th
public int getId()//return the id of the room
public String getPercorsi(int i)//return the path from the object room to
the room with id equals to i
public boolean verifyVicino(int v)//This method verify if a room with id
equals to v is linked to the object room
The there are the method addVicino(int i) that insert i inthe array vicini,
the method setname, setid, getname, getid etc.
Data:
private int vicini[]=new int[4];//this array contains the id of the linked
rooms
public String percorsi[]= new String[9];//this array contain the path from
the object room to all the others rooms in percorsi[0] there is the path
from object room to the room with id=0, in percrosi[1] path from object room
to the room with id[1], etc.
private int id;//in this int there's the id of the room
private String nome;//in this string there's the name of the room
In the main I have an array that contains all the room of the museum(Room
museum[]=new Room[x]).
The I have created a class Path to determinate the shortest path from a room
to another room.
This is the class Path:
public class Path {
private Room start;
public Path(Room r){ //the constructor take a room the room of start
and set the path to the linked room
for(int i=0; i<r.getNumVicini(); i++){
r.verifica[r.getVicino(i)]=true; //r.getVicino(i) give the id of
the linked rooms and set the verify[x], where x is the id of the linked
room, to true, because the shortest path is immediate
r.percorsi[r.getVicino(i)]+=r.getId()+ " " +
r.getVicino(i);//set the path to the linked room i equals to the id of the
start room an the id of the end room in this case the is of the end room is
the id a linked room
}
start=r;//it assigns the object r to start
}
private void findRoad2(Room end){ //this method permit to calculate
the path from 2 rooms that have a common linked room, but I don't know how
do to determinate a path for 2 room if between these 2 rooms there is more
of one room for example if I have these room 2-9-6-8(hte number are the id
of the room , the - are the link), with this method I am able to
derterminate the path from 2 to 9, from 2 to 6, but not for 2 to 8
for(int i=0; i<start.getNumVicini(); i++){
for(int j=0; j<end.getNumVicini(); j++){
if(start.getVicino(i)==end.getVicino(j) &&
start.verifica[end.getId()]==false){//This cycle verify if there is a common
linked room(like the room 9 in the example of the path from 2to6)
start.verifica[end.getId()]=true; //if there is this
common linked room it sets the verify[end.getId()] to true to indicate that
the path it is been determinated
start.percorsi[end.getId()]=start.getId()+ " " +
start.getVicino(i) + " " + end.getId(); //set the path, this path is equals
to start id and the id of the common linked room and end room id
}
}
}
}
If I have a map of the museum of this type:
7-8-3
| | |
6-4-2
| | |
5-0-1
(this map is only an example I could have a museum with 13 rooms that are
arranged in irregular way)
with the code that I have written I can determinate the path from 7 to 8,
from 7 to 6, from 7 to 4, from 7 to 3 and from 7 to 5, but NOT from 7 to 0,
from 7 to 1 or from 7 to 2
At the same way I can determinate the path from 0 to 5, from 0 to 1m from 0
to 4, from 0 to 8, from 0 to 2, from 0 to 6, but NOT from 0 to 3, from 0 to
7.
The some thing is for the rest of the rooms. I don't know how do to
determinate the rest of the path.
How can I do?
Thanks and excuse me.
- 8
- Stack and Thread SafetyMay I assume that a stack is thread safe since it extends the
synchronized vector class?
Thanks.
--
Kenneth P. Turvey <email***@***.com>
Artificial Intelligence Algorithms Wiki
http://ai.squeakydolphin.com
- 8
- 12
- Ltd. Enrollment NotificationAttention Potential Candidate:
You may now qualify for our unique University Education Program. For a limited amount of students - No tests, classes, books, or interviews required*
Yourself, and a limited number of other candidates are invited to take advantage of this Special Enrollment
Bachelors, Masters, MBA, and Doctorate (PhD) available in the field of your choice - 100% Verifiable Documents will be shipped to you within 2 weeks.
CALL US 24-7 - This Special Enrollment Ends Soon
1 (310) 281 - 6248
Thank You
Erin Reilly,
Educational Counsellor,
Internet Admissions Office
*Education awarded on life and past work experience.
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 12
- Can start() method access applet parameters?I have a signed applet that needs to read in data passed from HTML
page
via PARAM elements defined in EMBED tag. Since I cannot launch a
method
directly via JavaScript (bug), I thought I'd try to see if I could get
the
code to run as needed via the start() method by reloading the page.
But my
applet is not recognizing the parameter values being passed in (when
output
for debugging, they show up as null). Can parameters be passed like
this to
the start() method??
Test HTML page:
<html>
<head><title>
Test a Signed Applet
</title></head>
<body>
<EMBED type="application/x-java-applet;jpi-version=1.4.2"
name="Launch" code="LaunchHSDXPlugIn.class"
archive="LaunchHSDXPlugIn.jar" WIDTH=120 HEIGHT=75
<PARAM NAME="ImageFile"
VALUE="\\ain-www06.devsrv\output\mapfile.jpg">
<PARAM NAME="VBCodeLocation"
VALUE="\\ain-www06.devsrv\RivCopy\CopytoClipboard.exe">
</EMBED>
<br><br>
<img name="copy" src="copy.png" onMouseDown="location.reload(true);">
</body>
</html>
Test JAVA code:
import java.applet.*;
import java.io.*;
public class LaunchHSDXPlugIn extends Applet
{
public void start()
{
System.out.println("\n** In start method.\n");
try
{
String getval = null;
getval = getParameter("ImageFile");
System.out.println("the imagefile is " + getval);
Runtime.getRuntime().exec("w:\\hyperionics\\hypersnap\\hsdx.exe -
fixed_title " + getval);
Thread.sleep(2500);
getval = getParameter("VBCodeLocation");
System.out.println("the vbcodelocation is " + getval);
Runtime.getRuntime().exec(getval);
}
catch (SecurityException e1)
{
System.out.println("\n** An access control error occurred
attempting to run LaunchHSDXPlugIn applet.\n");
e1.printStackTrace();
}
catch (IOException e2)
{
System.out.println("\n** Error attempting to execute HyperSnap or
copy to clipboard.\n");
e2.printStackTrace();
}
catch (Exception e3)
{
System.out.println("\n** An error occurred attempting to run
LaunchHSDXPlugIn applet.\n");
e3.printStackTrace();
}
}
}
- 12
- Oracle JDBC executeQuery() hanging with a to_char() in the selectCalling statement.executeQuery() hangs, anyone experienced this? Using
the Oracle thin driver v9.2.0.1.0 running on a Solaris 8 box. The
code:
Connection connection = cdrDataSource.getConnection();
Statement statement = connection.createStatement();
String sql = "SELECT
TO_CHAR(SOFIXML.SOFI_LIB.SOFI_GET_XML('CA89352LAC42', NULL, NULL))
FROM DUAL";
ResultSet resultSet = statement.executeQuery(sql);
if(resultSet.next()) {
return resultSet.getString(1);
}
The SOFI_GET_XML function returns a CLOB and I'm using TO_CHAR() to
convert is into a VARCHAR2 for speed. Not doing a TO_CHAR and
processing the CLOB works fine but is a little slow. The query runs
fine through both TOAD and SQLPlus.
Thanks, Chris
- 12
- problem with Retroguard and Java 2 JDK?Hello
I have previously used Retroguard with jdk 1.1.8 but am having
problems using j2sdk 1.4.2_03. Get the following errors in the log
file. Any ideas why please?! The scr and run batch files which I am
using follow the error messages...
Geoff
# Unrecoverable error during obfuscation:
# java.lang.ClassNotFoundException:
symantec.itools.awt.util.dialog.ModalDialog
java.lang.ClassNotFoundException:
symantec.itools.awt.util.dialog.ModalDialog
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at a.a.a.f.a(Unknown Source)
at a.a.a.f.a(Unknown Source)
at a.a.a.f.j(Unknown Source)
at a.a.a.j$4.a(Unknown Source)
at a.a.a.j.a(Unknown Source)
at a.a.a.j.a(Unknown Source)
at a.a.a.j.a(Unknown Source)
at a.a.a.j.a(Unknown Source)
at a.a.a.j.a(Unknown Source)
at a.a.a.j.if(Unknown Source)
at a.a.a.s.do(Unknown Source)
at a.a.a.s.a(Unknown Source)
at RetroGuard.a(Unknown Source)
at RetroGuard.a(Unknown Source)
at RetroGuard.main(Unknown Source)
1. scr batch file
set CLASSPATH=d:\retro\retroguard.jar;d:\retro\symbeans.jar
c:\j2sdk1~1.2_0\bin\java -classpath %CLASSPATH% RGgui
2. run bacth file
set CLASSPATH=d:\retro\retroguard.jar;d:\retro\symbeans.jar
c:\j2sdk1.4.2_03\bin\java -classpath %CLASSPATH% RetroGuard 030204.jar
ob030204.jar 030204.rgs 030204.log
- 13
- Using pictures from the jar?
I create the jar with my classes, pictures and some txt files. The
application is starting just fine if picture folder is out of the jar.
If the folder picture is in the jar I don't see the pictures on my buttons
and everywhere.
How to solve that problem?
- 15
- wholesale,hoody ( paypal accept ) ( www.top-saler.com ) wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
- 16
- 16
- Event-Handling: Using one single class for different events?
Hi!
I am rather new to Java, so please, don't blame me for this question.
What I want is to seperate the GUI- from the Application code. Hence,
I have created three classes:
1. a Main class
2. a MainFrameCommand class, which parses the events
3. a MainFrameGUI class, that creates and paints the gui
(for a trivial example see end of this post)
Now, my question is this: Is it correct, to put all the various events
into one single command class (i.e, Focus-, Key-, Mouse-, and Windows-
Events) and then register the various event-listeners using this
single class?
It works perfectly, however, I wonder if this is a legal way to do so,
or is it necessary to create a seperate class for every different
event-listener-type?
Example:
------------------------------------------------------------
1. Main Class
------------------------------------------------------------
class Main {
public static void main(final String[] args) {
MainFrameCommand cmd = new MainFrameCommand();
MainFrameGUI gui = new MainFrameGUI(cmd);
}
}
------------------------------------------------------------
2. MainFrameCommand Class
------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class MainFrameCommand
implements KeyListener, MouseMotionListener, WindowListener {
/* Key Listener */
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}
/* MouseMotion Listener */
public void mouseMoved(MouseEvent event) {}
public void mouseDragged(MouseEvent event) {}
/* WindowListener */
public void windowClosed(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
public void windowClosing(WindowEvent event) {}
public void windowActivated(WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
}
------------------------------------------------------------
3. MainFrameGUI Class
------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class MainFrameGUI extends Frame {
public MainFrameGUI(MainFrameCommand cmd) {
super("Window");
setSize(300, 300);
setVisible(true);
/* !!!!!!!!!!!!!!!!!!!!!!! HERE'S THE CRUCIAL QUESTION
!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!! Is it legal to add register all these
!!!!!!!!!!!!!!!!!!!!!!! event listeners using the same object?!?
*/
addKeyListener(cmd);
addWindowListener(cmd);
addMouseMotionListener(cmd);
}
public void paint(Graphics g) {}
}
- 16
- Accessing the associated dataModel when a particular frame is selectedI have JDesktop containing one or more JInternalFrames. Each of these
frames contains a JScrollPane which in turn contains a JTable, each
with its own tableModel. I wish to add a row to the table in the
currently selected frame. How do I recover the tableModel to do this?
I can do it if I only have a single table using:
table.getModel().addRow(item);
but it would be easier for my end users if they could have multiple
tables open. The tables all have the same structure but have differing
numbers of rows. I also may need to edit existing items in the tables.
In line with the MVC architecture of Swing, it appears as if I am
trying to get to the model through the view rather than keeping the
model separate. This implies that I should keep a list (collection?)
of each model as I create it in my application. The difficulty then
becomes associating the currently selected view with the appropriate
model so that the editing is done in the appropriate table.
Any ideas or suggestions?
Oh, and a happy new year to everyone :-)
Bob
|
| Author |
Message |
Pep

|
Posted: 2005-10-27 6:37:00 |
Top |
java-programmer, Problem communicating with socket application
I am experiencing problems when trying to communicate with a TCP socket
based application that does not always append a <CR> at the end of the data
and so cannot use readLine on a BufferedInputStream.
I have tried using a simple read in to a char array but have found that
where the application has sent 4 records using 4 separate socket writes, my
read operation has resulted in them all being read in to one array and I
have no means of determining where one record ends and the next begins,
unless there are <CR> appended to each record, which as I stated is not
always the case :(
Using a normal unix socket read operation in C++ I would not have this
problem as each read operation would result in one record.
How can I get java sockets to operate in a similar manner as unix socket
reads so that one record is obtained in each read operation, regardless of
whether it is appended with a <CR> or not?
TIA,
Pep.
|
| |
|
| |
 |
Gordon Beaton

|
Posted: 2005-10-27 15:08:00 |
Top |
java-programmer >> Problem communicating with socket application
On Wed, 26 Oct 2005 23:37:29 +0100, Pep wrote:
> I am experiencing problems when trying to communicate with a TCP
> socket based application that does not always append a <CR> at the
> end of the data and so cannot use readLine on a BufferedInputStream.
>
> I have tried using a simple read in to a char array but have found
> that where the application has sent 4 records using 4 separate
> socket writes, my read operation has resulted in them all being read
> in to one array and I have no means of determining where one record
> ends and the next begins, unless there are <CR> appended to each
> record, which as I stated is not always the case :(
>
> Using a normal unix socket read operation in C++ I would not have
> this problem as each read operation would result in one record.
No, you've just been lucky so far. Your C++ application is broken too,
but has been working "by accident". A subtle difference in timing may
make the difference.
> How can I get java sockets to operate in a similar manner as unix
> socket reads so that one record is obtained in each read operation,
> regardless of whether it is appended with a <CR> or not?
TCP is a lowly byte stream, and it does not know anything about record
boundaries, nor does it make any attempts to preserve them. You may
find that multiple records are occasionally combined, and single
records are somtimes broken into two or more parts.
If you need delimited records you need to manage them yourself. The
easiest way is to insert delimiters (special characters like CR or
anything else that can't occur within a record) between the records as
you send them, so the recipient can determine where one record in the
stream ends and the next one begins.
Another way is to precede each record with a short header containing
the length of the record.
If you already know the length of each record in advance, simply read
the correct number of bytes from the stream each time.
Finally, maybe there is some other mechanism you can use in your
client to recognize the end of a record.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-27 15:31:00 |
Top |
java-programmer >> Problem communicating with socket application
On 27 Oct 2005 09:07:37 +0200, Gordon Beaton <email***@***.com> wrote,
quoted or indirectly quoted someone who said :
>Another way is to precede each record with a short header containing
>the length of the record.
>
>If you already know the length of each record in advance, simply read
>the correct number of bytes from the stream each time.
>
>Finally, maybe there is some other mechanism you can use in your
>client to recognize the end of a record.
and yet another way is an ObjectStream that deals with breaking the
stream up into objects for you. That won't work though when one end is
C++.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 16:31:00 |
Top |
java-programmer >> Problem communicating with socket application
Gordon Beaton wrote:
> On Wed, 26 Oct 2005 23:37:29 +0100, Pep wrote:
>> I am experiencing problems when trying to communicate with a TCP
>> socket based application that does not always append a <CR> at the
>> end of the data and so cannot use readLine on a BufferedInputStream.
>>
>> I have tried using a simple read in to a char array but have found
>> that where the application has sent 4 records using 4 separate
>> socket writes, my read operation has resulted in them all being read
>> in to one array and I have no means of determining where one record
>> ends and the next begins, unless there are <CR> appended to each
>> record, which as I stated is not always the case :(
>>
>> Using a normal unix socket read operation in C++ I would not have
>> this problem as each read operation would result in one record.
>
> No, you've just been lucky so far. Your C++ application is broken too,
> but has been working "by accident". A subtle difference in timing may
> make the difference.
>
I'm surprised I've been "lucky so far". I'm talking about a application
that services transactions from multiple clients under extreme load and it
has never missed a record yet. The records are passed using a normal socket
write operation so I know how the data is provided.
Still I won't argue with someone that knows better than me and by that I am
actually trying to be sincere not rude :)
>> How can I get java sockets to operate in a similar manner as unix
>> socket reads so that one record is obtained in each read operation,
>> regardless of whether it is appended with a <CR> or not?
>
> TCP is a lowly byte stream, and it does not know anything about record
> boundaries, nor does it make any attempts to preserve them. You may
> find that multiple records are occasionally combined, and single
> records are somtimes broken into two or more parts.
>
> If you need delimited records you need to manage them yourself. The
> easiest way is to insert delimiters (special characters like CR or
> anything else that can't occur within a record) between the records as
> you send them, so the recipient can determine where one record in the
> stream ends and the next one begins.
>
> Another way is to precede each record with a short header containing
> the length of the record.
>
> If you already know the length of each record in advance, simply read
> the correct number of bytes from the stream each time.
>
> Finally, maybe there is some other mechanism you can use in your
> client to recognize the end of a record.
>
> /gordon
>
Unfortunately I do not have control over the data being sent to me now and I
have now found from a ethereal analysis that sometimes the records have a
<CR> ending and other times they do not.
I'll have to try simply reading a determined number of bytes :(
Cheers,
Pep
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 16:32:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On 27 Oct 2005 09:07:37 +0200, Gordon Beaton <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>Another way is to precede each record with a short header containing
>>the length of the record.
>>
>>If you already know the length of each record in advance, simply read
>>the correct number of bytes from the stream each time.
>>
>>Finally, maybe there is some other mechanism you can use in your
>>client to recognize the end of a record.
>
> and yet another way is an ObjectStream that deals with breaking the
> stream up into objects for you. That won't work though when one end is
> C++.
>
Yep, unfortunately this data is being provided by some windows based c++
program.
Cheers,
Pep.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 16:35:00 |
Top |
java-programmer >> Problem communicating with socket application
Pep wrote:
> Gordon Beaton wrote:
>
>> On Wed, 26 Oct 2005 23:37:29 +0100, Pep wrote:
>>> I am experiencing problems when trying to communicate with a TCP
>>> socket based application that does not always append a <CR> at the
>>> end of the data and so cannot use readLine on a BufferedInputStream.
>>>
>>> I have tried using a simple read in to a char array but have found
>>> that where the application has sent 4 records using 4 separate
>>> socket writes, my read operation has resulted in them all being read
>>> in to one array and I have no means of determining where one record
>>> ends and the next begins, unless there are <CR> appended to each
>>> record, which as I stated is not always the case :(
>>>
>>> Using a normal unix socket read operation in C++ I would not have
>>> this problem as each read operation would result in one record.
>>
>> No, you've just been lucky so far. Your C++ application is broken too,
>> but has been working "by accident". A subtle difference in timing may
>> make the difference.
>>
>
> I'm surprised I've been "lucky so far". I'm talking about a application
> that services transactions from multiple clients under extreme load and it
> has never missed a record yet. The records are passed using a normal
> socket write operation so I know how the data is provided.
>
> Still I won't argue with someone that knows better than me and by that I
> am actually trying to be sincere not rude :)
>
>>> How can I get java sockets to operate in a similar manner as unix
>>> socket reads so that one record is obtained in each read operation,
>>> regardless of whether it is appended with a <CR> or not?
>>
>> TCP is a lowly byte stream, and it does not know anything about record
>> boundaries, nor does it make any attempts to preserve them. You may
>> find that multiple records are occasionally combined, and single
>> records are somtimes broken into two or more parts.
>>
>> If you need delimited records you need to manage them yourself. The
>> easiest way is to insert delimiters (special characters like CR or
>> anything else that can't occur within a record) between the records as
>> you send them, so the recipient can determine where one record in the
>> stream ends and the next one begins.
>>
>> Another way is to precede each record with a short header containing
>> the length of the record.
>>
>> If you already know the length of each record in advance, simply read
>> the correct number of bytes from the stream each time.
>>
>> Finally, maybe there is some other mechanism you can use in your
>> client to recognize the end of a record.
>>
>> /gordon
>>
>
> Unfortunately I do not have control over the data being sent to me now and
> I have now found from a ethereal analysis that sometimes the records have
> a <CR> ending and other times they do not.
>
> I'll have to try simply reading a determined number of bytes :(
>
> Cheers,
> Pep
Sorry I forgot to add that the length of the record is variable so that
without this random <CR> I'm pretty much screwed :(
|
| |
|
| |
 |
Gordon Beaton

|
Posted: 2005-10-27 16:51:00 |
Top |
java-programmer >> Problem communicating with socket application
On Thu, 27 Oct 2005 09:34:57 +0100, Pep wrote:
> Sorry I forgot to add that the length of the record is variable so
> that without this random <CR> I'm pretty much screwed :(
Probably, yes. I thought to add that exact sentiment in my previous
reply, but didn't want to come across as rude!
It sounds odd to me that the existence (or lack) of CR is "random".
Have I understood correctly that your C++ clients work as expected,
and you are now implementing a Java client to an existing C++ server?
Do the C++ clients not have any special logic to deal with record
boundaries? Can you not change the way the server sends messages?
As I mentioned earlier, a small timing change could make a difference.
Basically if there is a short delay between calls to write(), it is
often the case that they will be sent separately by TCP. As long as
the recipient reads() sufficiently quickly, he will receive them
separately as well. This can work ("by accident"), but you really
shouldn't rely on this behaviour.
If the sender sends short messages without delay in between, then TCP
may send them together. Similarly when the reader is slow, messages
will accumulate in his receive buffer, and calls to read() cannot
distinguish between them.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 18:02:00 |
Top |
java-programmer >> Problem communicating with socket application
Gordon Beaton wrote:
> On Thu, 27 Oct 2005 09:34:57 +0100, Pep wrote:
>> Sorry I forgot to add that the length of the record is variable so
>> that without this random <CR> I'm pretty much screwed :(
>
> Probably, yes. I thought to add that exact sentiment in my previous
> reply, but didn't want to come across as rude!
>
> It sounds odd to me that the existence (or lack) of CR is "random".
Same here. I was told in the spec that the records would be capped with a
<CR> but they are not always which is something I am arguing with the
designer of the server code.
>
> Have I understood correctly that your C++ clients work as expected,
> and you are now implementing a Java client to an existing C++ server?
>
NO. The original application which I wrote consisted of a C++ server and
client both of which use unix sockets with no EOR delimiter and they work
fine.
Now I am having to replace this with a server that is provided and has been
written using windows based C++ and I have to write the client. So I have
done this using java.
> Do the C++ clients not have any special logic to deal with record
> boundaries? Can you not change the way the server sends messages?
>
> As I mentioned earlier, a small timing change could make a difference.
>
> Basically if there is a short delay between calls to write(), it is
> often the case that they will be sent separately by TCP. As long as
> the recipient reads() sufficiently quickly, he will receive them
> separately as well. This can work ("by accident"), but you really
> shouldn't rely on this behaviour.
>
Accepted and thanks for that knowledge.
> If the sender sends short messages without delay in between, then TCP
> may send them together. Similarly when the reader is slow, messages
> will accumulate in his receive buffer, and calls to read() cannot
> distinguish between them.
>
Which appears to be my problem here.
> /gordon
>
Okay this is the code that I am trying to run
===============================================================================
try
{
while ((running.get()) && (parentProxy.br != null) &&
(parentProxy.br.ready()))
{
try
{
mResponse = "";
if (parentProxy.br != null)
{
mResponse = parentProxy.br.readLine(); // read the response from the m
server
logDebugToFile("TSreader::run processing [" + mResponse + "]");
parentProxy.processMResult(mResponse); // send the result back to the
client
}
}
catch(SocketTimeoutException e)
{
// do nothing here
}
}
}
catch(Throwable e)
{
logFatalToFile("TSreader::run Error (running) " + e.getMessage(), e);
e.printStackTrace();
}
===============================================================================
and this is the output of the code
===============================================================================
27 Oct 2005 09:34:15 GMT: DEBUG - {Thread-0} {Thread-4}
TSreader::run processing [CCOK Q458000:Y:a:XXXX48]
27 Oct 2005 09:34:16 GMT: DEBUG - {Thread-0} {Thread-4}
TSreader::run processing []
27 Oct 2005 09:34:16 GMT: FATAL - {Thread-0} {Thread-4}
TSreader::run Error (running) String index out of range: 6
java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.charAt(Unknown Source)
at TS.MP.processMResult(MP.java:486)
at TS.TSreader.run(TSreader.java:81)
at java.lang.Thread.run(Unknown Source)
27 Oct 2005 09:34:16 GMT: DEBUG - {Thread-0} {Thread-4}
TSreader::run processing [CCOK E458000:Y:a:XXXX34]
===============================================================================
as can be seen, it can read the first record and the 3rd record but the
second record is coming back empty
Based on this input on the socket (obtained using ethereal)
===============================================================================
CCOK
Q458000:Y:a:XXXX48C\x9f`C\xd8@^@6^@^@^@6^@^@^@^@^N\x83\x9c\x91\xb2^@^K\xdb\x95\xc
(^H^@E^@^@(V\xbf@^@@^F^@^@\xc0\xa8j\xac^]^H^P\x8f
\xbc#\x8d\xf5\x95\xd4\xd3\xd1\x83^G\xfdP^P\xe4
Y^F^@^@C\x9f`C\xdbC^@<^@^@^@<^@^@^@^@^K\xdb\x95\xc
(^@^N\x83\x9c\x91\xb2^H^@E^@^@)^O\xf5@^@}^F\x94\xee^]^H^P\x8f\xc0\xa8j\xac#\x8d\xbc\xd1\x83^G\xfd\xf5\x95\xd4\xd3P^X^^^[Z\x91^@^@^M^@^@^@^@^@C\x9f`C\x8en^@\x87^@^@^@\x87^@^@^@^@^N\x83\x9c\x91\xb2^@^K\xdb\x95\xc
(^H^@E^@^@yV\xc6@^@@^F^@^@\xc0\xa8j\xac^]^H^P\x8f
\xbc#\x8d\xf5\x95\xd4\xd3\xd1\x83^G\xfeP^X\xe4YW^@^@C:MISTER-48/5 :WXYZ :4111111111111111 :0605:
20.00:JTWB801XXXX48 ^MC\x9f`C\xab\x86^@M^@^@^@M^@^@^@^@^K\xdb\x95\xc
(^@^N\x83\x9c\x91\xb2^H^@E^@^@?^P\xf5@^@}^F\x93\xd8^]^H^P\x8f\xc0\xa8j\xac#\x8d
\xbc\xd1\x83^G\xfe\xf5\x95\xd5$P^X^]\xca\x88g^@^@CCOKR458000:Y:a:XXXX10C\x9f`C8\xb7^K^@\x87^@^@^@\x87^@^@^@^@^N\x83\x9c\x91\xb2^@^K\xdb\x95\xc
(^H^@E^@^@yV\xcc@^@@^F^@^@\xc0\xa8j\xac^]^H^P\x8f
\xbc#\x8d\xf5\x95\xd5$\xd1\x83^H^UP^X\xe4
YW^@^@C:MISTER-18/5 :WXYZ :4111111111111111 :0605:
20.00:KTWB801XXXX18 ^MC\x9f`C\xba^K^@O^@^@^@O^@^@^@^@^K\xdb\x95\xc
(^@^N\x83\x9c\x91\xb2^H^@E^@^@A^R\xf5@^@}^F\x91\xd6^]^H^P\x8f\xc0\xa8j\xac#\x8d
\xbc\xd1\x83^H^U\xf5\x95\xd5uP^X^]yE~^@^@^MCCOK
E458000:Y:a:XXXX34^MC\x9f`C^K'^M^@6^@^@^@6^@^@^@^@^N\x83\x9c\x91\xb2^@^K\xdb\x95\xc
(^H^@E^@^@(V\xd1@^@@^F^@^@\xc0\xa8j\xac^]^H^P\x8f
\xbc#\x8d\xf5\x95\xd5u\xd1\x83^H.P^P\xe4Y^F^@^@C\x9f`C\xf3\xdd^M^@M^@^@^@M^@^@^@^@^K\xdb\x95\xc
(^@^N\x83\x9c\x91\xb2^H^@E^@^@?^T\xf5@^@}^F\x8f\xd8^]^H^P\x8f\xc0\xa8j\xac#\x8d
\xbc\xd1\x83^H.\xf5\x95\xd5uP^X^]y\x82F^@^@
===============================================================================
and I am struggling to find out why this is happening :(
If you can see where I am going wrong then I would greatly appreciate your
advice.
The really annoying thing is that I have written a simulator based on the
servers spec of capping the records with a <CR> and my client can process
up to 100,000 record sin a 2 hour period. So this is really starting to
piss me off!
Cheers,
Pep.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-27 18:28:00 |
Top |
java-programmer >> Problem communicating with socket application
On Thu, 27 Oct 2005 11:01:34 +0100, Pep <email***@***.com> wrote,
quoted or indirectly quoted someone who said :
>Same here. I was told in the spec that the records would be capped with a
><CR> but they are not always which is something I am arguing with the
>designer of the server code.
If you are using a BufferedOutputStream, you want to do a flush()
after every record or parts of it could stay stuck in the buffer
wrapping the socket until you write some more to push it out.
.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 18:43:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On Thu, 27 Oct 2005 11:01:34 +0100, Pep <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>Same here. I was told in the spec that the records would be capped with a
>><CR> but they are not always which is something I am arguing with the
>>designer of the server code.
>
> If you are using a BufferedOutputStream, you want to do a flush()
> after every record or parts of it could stay stuck in the buffer
> wrapping the socket until you write some more to push it out.
> .
>
I'm using a print writer
pw = new PrintWriter(microgateSocket.getOutputStream(),true);
The really annoying thing about this is that it seems ot be related to the
fact that they are not placing a <CR> at the end of the records. My
simulator puts a \n at the end of each record and like I said, my client
will then process over 100,000 record swithout dropping a single one.
Cheers,
Pep.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 18:47:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On Thu, 27 Oct 2005 11:01:34 +0100, Pep <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>Same here. I was told in the spec that the records would be capped with a
>><CR> but they are not always which is something I am arguing with the
>>designer of the server code.
>
> If you are using a BufferedOutputStream, you want to do a flush()
> after every record or parts of it could stay stuck in the buffer
> wrapping the socket until you write some more to push it out.
> .
>
Actually as I am looking at the ethereal output, I cannot see a <CR> at the
end of any of the records they are seeing back to me at all so I'm now
wondering how the readLine function is working at all?
Cheers,
Pep.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-27 19:05:00 |
Top |
java-programmer >> Problem communicating with socket application
On Thu, 27 Oct 2005 11:42:42 +0100, Pep <email***@***.com> wrote,
quoted or indirectly quoted someone who said :
>pw = new PrintWriter(microgateSocket.getOutputStream(),true);
>
>The really annoying thing about this is that it seems ot be related to the
>fact that they are not placing a <CR> at the end of the records.
That is not the official duty of a PrintWriter. It is supposed to put
a platform specific line separator there. If you want a cr
specifically you should do a write( '\r' );
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 19:26:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On Thu, 27 Oct 2005 11:42:42 +0100, Pep <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>pw = new PrintWriter(microgateSocket.getOutputStream(),true);
>>
>>The really annoying thing about this is that it seems ot be related to the
>>fact that they are not placing a <CR> at the end of the records.
>
> That is not the official duty of a PrintWriter. It is supposed to put
> a platform specific line separator there. If you want a cr
> specifically you should do a write( '\r' );
Yeah but they are not using a print writer. They have written their
application using either Visual C++ or Visual Basic so maybe god knows how
they are writing the data to the socket?
I use the print writer in my java client to send the transactions to their
server and I append a <CR> to the data.
I have just done another massive run against their server and they seem to
only be appending a <CR> to maybe around 2% of their transaction reply
records. Which of course means as it is a variable length record with no
delimiter I cannot even handle the protocol myself using a data stream
reader.
Cheers,
Pep.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-27 23:03:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On Thu, 27 Oct 2005 11:42:42 +0100, Pep <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>pw = new PrintWriter(microgateSocket.getOutputStream(),true);
>>
>>The really annoying thing about this is that it seems ot be related to the
>>fact that they are not placing a <CR> at the end of the records.
>
> That is not the official duty of a PrintWriter. It is supposed to put
> a platform specific line separator there. If you want a cr
> specifically you should do a write( '\r' );
I have now found out, with the use of ethereal at both ends of the socket,
that the windows application is definitely sending a 0x0D but it is being
transformed in to a 0xDC by the time it reaches my end of the socket.
Similarly my 0x0D0x0A byte sequence is being converted in to a 0x0d.
Cheers,
Pep.
|
| |
|
| |
 |
Gordon Beaton

|
Posted: 2005-10-27 23:21:00 |
Top |
java-programmer >> Problem communicating with socket application
On Thu, 27 Oct 2005 16:02:45 +0100, Pep wrote:
> I have now found out, with the use of ethereal at both ends of the
> socket, that the windows application is definitely sending a 0x0D
> but it is being transformed in to a 0xDC by the time it reaches my
> end of the socket.
I find it extremly hard to believe that the cable or a switch alone
would be making such selective changes to the data stream.
Are you absolutely certain that you aren't making parts of this
observation in the code itself, where some processing has already
taken place? Or that your data doesn't pass through a proxy of some
kind?
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-28 3:43:00 |
Top |
java-programmer >> Problem communicating with socket application
Gordon Beaton wrote:
> On Thu, 27 Oct 2005 16:02:45 +0100, Pep wrote:
>> I have now found out, with the use of ethereal at both ends of the
>> socket, that the windows application is definitely sending a 0x0D
>> but it is being transformed in to a 0xDC by the time it reaches my
>> end of the socket.
>
> I find it extremly hard to believe that the cable or a switch alone
> would be making such selective changes to the data stream.
>
> Are you absolutely certain that you aren't making parts of this
> observation in the code itself, where some processing has already
> taken place? Or that your data doesn't pass through a proxy of some
> kind?
>
> /gordon
>
At this point I am not sure of anything other than ethereal shows a 0x0D on
the windows end of the socket and a 0xDC on the unix end of the socket.
Similarly that the 0x0D0x0A on the unix end of the socket is a 0x0D when it
reaches the windows end of the socket.
I make no assumptions as to what is causing the change but am relieved to
find out that it is not my client written in Java or the server written in
some windows based language.
Cheers,
Pep.
|
| |
|
| |
 |
Steve Horsley

|
Posted: 2005-10-29 4:21:00 |
Top |
java-programmer >> Problem communicating with socket application
Pep wrote:
>
> At this point I am not sure of anything other than ethereal shows a 0x0D on
> the windows end of the socket and a 0xDC on the unix end of the socket.
>
> Similarly that the 0x0D0x0A on the unix end of the socket is a 0x0D when it
> reaches the windows end of the socket.
>
> I make no assumptions as to what is causing the change but am relieved to
> find out that it is not my client written in Java or the server written in
> some windows based language.
>
Spooky. So what exactly connects the client and server?
As Gordon says, I imagine they must be talking via a proxy. I
would be inclined to compare the traces for IP address, MAC
address, IP sequence numbers, to prove there is some entity
playing piggy in the middle and corrupting the data stream. That
kind of change doesn't happen by accident - you have to re-write
checksums, and even change sequence numbering if you're dropping
bytes from the stream.
Steve
|
| |
|
| |
 |
Missaka Wijekoon

|
Posted: 2005-10-29 13:01:00 |
Top |
java-programmer >> Problem communicating with socket application
Pep wrote:
>
> Actually as I am looking at the ethereal output, I cannot see a <CR> at the
> end of any of the records they are seeing back to me at all so I'm now
> wondering how the readLine function is working at all?
Per the Java API docs:
public String readLine() throws IOException
Read a line of text. A line is considered to be terminated by any
one of a line feed ('\n'), a carriage return ('\r'), or a carriage
return followed immediately by a linefeed.
From some of the conversation, it feels as if there might be a filter
that is converting the stream like dos2unix, etc. Is there a chance
that the socket on the server end is not a true socket, but perhaps a
telnet connections? For example, the telnet protocol requires that 0xFF
be escaped.
> Cheers,
> Pep.
>
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-29 14:59:00 |
Top |
java-programmer >> Problem communicating with socket application
On Thu, 27 Oct 2005 16:02:45 +0100, Pep <email***@***.com> wrote,
quoted or indirectly quoted someone who said :
>
>I have now found out, with the use of ethereal at both ends of the socket,
>that the windows application is definitely sending a 0x0D but it is being
>transformed in to a 0xDC by the time it reaches my end of the socket.
So Java nothing to do with it.
Write a class that reads one record scanning it byte by byte
You might use http://mindprod.com/jgloss/readblocking.html
as a model. Perhaps it should also convert it to char for you as well
after it has scanned the bytes.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
| |
|
| |
 |
Pep

|
Posted: 2005-10-31 19:15:00 |
Top |
java-programmer >> Problem communicating with socket application
Roedy Green wrote:
> On Thu, 27 Oct 2005 16:02:45 +0100, Pep <email***@***.com> wrote,
> quoted or indirectly quoted someone who said :
>
>>
>>I have now found out, with the use of ethereal at both ends of the socket,
>>that the windows application is definitely sending a 0x0D but it is being
>>transformed in to a 0xDC by the time it reaches my end of the socket.
>
> So Java nothing to do with it.
>
Thankfully, no.
> Write a class that reads one record scanning it byte by byte
>
> You might use http://mindprod.com/jgloss/readblocking.html
> as a model. Perhaps it should also convert it to char for you as well
> after it has scanned the bytes.
>
Just about to run my client on the same network segmet as the server to see
if we still have the same problem. If not then we can work outwards from
there to see where it comes in.
Cheers,
Pep.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Available memory and limit on thread creationJoseph Dionne wrote:
<snip>
>> Of course if you only had a J2EE server...
>> Seriously, this is the sort of situation where you could justify
>> the complexity and expense. Stateless or even stateful session
>> EJBs would fit the bill. Let the container manage the details.
>> Why re-invent the wheel?
>
> Because I have a frugal customer who is already not terribly excited
> about paying my bill? The real world sucks!
Read Roedy's reply carefully. He was able to succinctly describe the
limitations of the HTTP protocol, namely that it's stateless. What I
would suggest you consider is a hybrid of available technologies.
Given what you've described to-date, I would lean towards a JMS
solution. This would provide "loose coupling" and incorporates some
of Roedy's suggestions in terms of queueing requests/responses.
Insofar as J2EE servers, have you had a look at JBoss? While I
wouldn't recommend it for commercial, mission-critical applications,
it can serve as a powerful development platform when linked with the
Eclipse IDE. It might be enough to demonstrate to your client that
there IS a better way.
I'm just throwing out suggestions as what you're describing is quite
complex and would involve a major investment in time for development.
That will translate to $$, no matter how much or little you charge
per hour.
- 2
- 3
- Newbie question on stopping an applicationI have a simple console application that prompts the user to enter two
numbers and then the program multiplies these two numbers and spits out
the product. No problem so far. The difficulty I'm having is that if
someone enters a negative number, I want the program to reply something
like "Does not accept negative numbers!" then stop. I tried using
"break;" but it generated an error message and said that I was using it
"outside the loop" or something like that. I would be grateful if
someone could give me a clue on what I might use for this. Thank you
very much. My code is below.
public class Kilowatt
{
private double costKiloWattHours; //example 8.42 which means cents
private double hoursUsedPerYear; //example 653
private double annualCost;
public void setCost(double cost)
{
if (cost <= 0)
{
//I want the program to say "You can't enter a negative number."
//Then the program should stop execution.
}
else
{
costKiloWattHours = cost / 100;
}
}
public void setHours(double hours)
{
hoursUsedPerYear = hours;
}
public double getAnnualCost()
{
annualCost = costKiloWattHours * hoursUsedPerYear;
return annualCost;
}
}
import java.util.Scanner;
class Kilowatt_Test
{
public static void main(String[] args)
{
double myCost;
double myHours;
Scanner myScanner = new Scanner(System.in);
System.out.print("What's the cost per kilowatt hour? ");
myCost = myScanner.nextDouble();
Kilowatt myKilowatt = new Kilowatt();
myKilowatt.setCost(myCost);
System.out.print("How many kilowatt-hours are used per year? ");
myHours = myScanner.nextDouble();
myKilowatt.setHours(myHours);
System.out.println("The annual cost is: " +
myKilowatt.getAnnualCost());
}
}
- 4
- ATL - Sr. Java Developers @ www.StatCom.com - Hospital Patient Flow Logistics SoftwareSr. Java Technical Lead
Do you enjoy working with the best of the best software developers? How
about working on one of the hospital industries most important
technological innovations?
SEND RESUME & COVER LETTER TO : email***@***.com
OR call 770.643.5640
StatCom http://www.statcom.com - a division of Jackson Healthcare
Solutions - , located in Alpharetta, GA is seeking a senior Java
Software development professional with an in depth knowledge of complex
application development using the latest tools and techniques Java
offers.
StatCom is a leading developer of real-time, web-based healthcare
software. We have an excellent opportunity for a Sr. Java
Developer/Technical Lead who is a self starter who thrives in an
entrepreneurial and creative development environment.
Required Skills
?Sr. Java Developer with a minimum of 5+ years of Java development
experience.
?Candidates should have excellent technical expertise with Java along
with excellent written and verbal communication skills.
?You must be comfortable in a dynamic, fast paced, high tech,
entrepreneurial environment.
?You will do hands on development and technical mentoring.
?You must be comfortable working with loose specifications.
?Healthcare industry experience is a plus.
?Complex distributed application development experience is desirable.
________________________________________________________
Technical Environment:
Operating systems:
?Windows, UNIX, Linux
Programming languages:
?Java, JSP, J2EE, Servlets, HTML, Javascript, XML; Actionscript
Development tools:
?Oracle, SQL
JOB DESCRIPTION:
1. The ideal candidate will be responsible for designing and writing
production code for the Statcom applications and is expected to be able
to analyze requirements and take responsibility for implementing the
features to completion.
2. Our working environment encourages discussion to figure out the
right way to get the job done, but also how to move quickly when
necessary.
3. Will be working on highly multi-threaded server applications and MVC
based GUIs.
4. Will get opportunities to upgrade expertise and skills through
mentoring and training.
5. Will learn the latest software development practices, methods
conventions and standards as executed within the company.
6. Our use of technologies include our own real-time messaging system,
rules engine, dynamic display and forms technology written in server
side java with the presentation layer using flash and jsp.
7. This position is based in Atlanta.
About StatCom http://www.statcom.com:
Because StatCom is Web-based, only Internet Explorer and Macromedia
Flash plug-ins are required on the client side. StatCom monitors data
in real-time from information systems such as HIS, scheduling, asset
tracking and ADT. It also acquires event, location and date/time data
from an array of input devices:
StatCom Web displays, located on
?Plasma displays
?Workstations
?Tablet PCs
StatCom WIBUT
StatCom TIP
Barcode scanners and RFID
Telephone/IVR
PDAs
Other devices customized to the client's specifications
StatCom takes the acquired data and uses its rules-based workflow
engine and message router to drive two actions critical to patient
flow: instant communication and automated workflow. In other words, it
determines to whom or where to send the data (instant communication),
as well as the correct message to facilitate the next action (automated
workflow).
RECENT NEWS ABOUT US
Jackson Healthcare Solutions Hits $100 Million in Revenue
Some of the milestones JHS has achieved in the past year are:
?September 2005 JHS ranked in the Top 10 A+Employers and best places
to work , according to the Atlanta Business Chronicle.
?April 2005 JHS is one of the Top 25 fastest growth Atlanta based
companies in 2005, according to the Atlanta Business Chronicle.
?December 2004 JHS is one of the Top 10 privately held Atlanta
Healthcare Companies in 2005, according to INC 500 magazine.
?From 2000-2005, Jackson Healthcare Solutions revenues have
skyrocketed from $20,000,000 to $137,000,000.
?May 2005 - JHS unveiled our technology vision center - HI-TECH
Virtual hospital simulation suite
Benefits
We provide competitive compensation and an attractive benefits package,
offering:
Medical, dental and vision care insurance
Health Care and Dependent Care Personal Spending Accounts
Life Insurance
Short and Long-Term Disability Insurance
401(K) plan with company match
Paid Vacation
Paid Holidays
- 5
- java parserHello,
I am new to programming and I need to create a parser for an
application using java. I am using J++ to complete this task. Any
help or advice would be greatly appreciated.
Also, Can anyone assist me in creating a simple progress bar?
Thanks,
Brad
- 6
- Progress bar to show the progress of a taskIn my application one click on the start button will fire one specific
task which includes some numerical computation routines and data
visualization routines.
Want to use progress bar to show the progress of the task execution,
even after reading sun's java swing tutorials still not clear how to
set the maximum length of the progress bar and update the progress
status.
Really appreciate your time and kind help!
Thanks a lot.
- 7
- Applet and browser pageHello, all !!!
I have HTML page with radio buttons.
And there is an applet on this page.
How can applet find out, radio selection ?
Thanx.
- 8
- HTTP/1.1 persistent connections
(Sorry, can't post any complete example code for this at the minute
which is really annoying, I know.)
AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
my situation), repeated connections to the same host will re-use an
existing established HTTP connection. This appears to be the case for
normal HTTP URLS - I'm doing something like this:
URL url = new URL("http://guff.here.etc/");
HttpURLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
osw = new OutputStreamWriter(httpURLConn.getOutputStream());
bw = new BufferedWriter(osw);
.. etc..
while I'm do this repeatedly in java, I can see by running 'netstat -a'
(windows 2000 machine) that there is indeed only one connection being used:
$ netstat -a | grep 199
TCP localhost:2282 remote.host.name:80 ESTABLISHED
$
..despite the fact that I'm doing many GETs from this URL. this is
desirable, only having one connection, as it uses less resources
(connector threads) in tomcat.
Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
connector on port 19929)
URL url = new URL("https://guff.here.etc:19929/");
HttpURLConnection urlConn = url.openConnection();
// call setDefaultSSLSocketFactory(...) here...
// set the HostVerifier here...
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
osw = new OutputStreamWriter(httpURLConn.getOutputStream());
bw = new BufferedWriter(osw);
...etc.
... it works, but each GET is spawning a new connection, and a new
connector thread on tomcat.
e.g. netstat gives me the following:
$ netstat -a | grep 199
TCP localhost:2049 remote.host.name:19929 ESTABLISHED
TCP localhost:2051 remote.host.name:19929 ESTABLISHED
TCP localhost:knetd remote.host.name:19929 ESTABLISHED
TCP localhost:2055 remote.host.name:19929 ESTABLISHED
TCP localhost:2057 remote.host.name:19929 ESTABLISHED
TCP localhost:2059 remote.host.name:19929 ESTABLISHED
TCP localhost:2061 remote.host.name:19929 ESTABLISHED
..[snipped many more lines like this!]....
Because the link isn't persistent like HTTP, tomcat soon runs out of
threads as it is using a thread for each connection, and I start getting
refused requests as a result of this.
I searched around in the usual places, and found someone with the same
problem, and it turned out the cause in his case was that he wasn't
calling close() on his OutputStreamWriter that was being used to feed
his query into his GET. I am calling close() here, however, so that's
not the problem...
Just on the offchance that someone is familiar with this problem!
thanks,
alex
- 9
- Newbies doubts on JavaHi All:
I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:
1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?
2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.
Thank you for your time in answering these naive questions.
- 10
- graphical calendar viewHello,
It seems that the standard Java library doesn't include a graphical
calendar component so I was wondering if anyone happens to know of a
free one, preferably one that is big enough that would allow text to be
readable on the individual days (to list daily tasks, etc.)?
If there isn't one, any ideas on how I'd go about creating my own based
on the info from the existing java.util.Calendar object? I assume I
would probably need to have a JTable created at the least. Any
suggestions on doing that are appreciated.
thanks
Brandon
- 11
- Problem with "if - else" statement in for loopI am having problems with this section of code...
public void updateRank(){
int x = -1;
int y = -1;
String winnerMemNum = JOptionPane.showInputDialog
("Enter winner's membership number:");
int wMemNum = Integer.parseInt(winnerMemNum);
for(int i=0;i<list.size();i++){
Player temp = (Player)list.get(i);
if(temp.getMemberNumber() == wMemNum)
x = i;
else
System.out.println("Player not found");
break;
}
I want the condition in the if statement to be tested for every element
in the list before the code in the else block executes, but at the
moment it is only testing the first element. I know I need to put
brackets in, but when I did that, the whole thing stopped working! Any
ideas?
- 12
- Java maybe, some help with something puzzlingHi all,
I was given this quiz as it were. I'm asked certain questions about
two snippets of code. The questions do not indicate the programming
language. I'm mainly familiar with java methods but don't know if other
languages would also use "methods." I'm also a bit confused because an
Array, which is indicated in the code below, should have the square brackets
[] and yet this code snippet is lacking that. Any advice on what I might
want to look at to understand this code further would be
greatly appreciated. Sorry if I seem ignorant here.
1. Consider the following method:
private int wrongCode(Integer num){
if (num > 6){
return num - 5;
} else {
return num.parseInt();
}
}
What are the errors?
2. Consider the following methods:
public int run() {
List group1 = new ArrayList();
for (int i=0;i<3;i++) {
group1.add(i);
}
List group2 = this.makeNewList(group1);
return group2.size() - group1.size();
}
private List makeNewList(List list) {
List other = list;
other.remove(other.size() - 1);
return other;
}
What value is returned from the method run() after it is called?
Thanks,
bruce
- 13
- ASM Help
I am trying to convert some asm to c. Learning asm as I go...
LINIT: .DB 38H ;
.DB 0CH ;
.DB 06H ;
LSIZZ .EQU $-LINIT ;
My question what is the LSOZZ equal?
- 14
- Java clock offsettable by minutes?I'm trying to find a Java clock applet that will allow me to offset the
minutes. Ideally, something attractive, customizable, TZ-sensitive *AND*
with a minutes offset.
I've searched pretty thoroughly, but that last requirement doesn't seem to
exist in the online archives. (Note that I mean a real minutes offset, not
just a 0030 TZ offset - i.e., make the clock run exactly 10 minutes slow or
15 minutes fast.)
Oh, and something outta the box... I'm, uh, not a Java programmer. :P
Ad(thanks)vance.
--
|=- James Gifford = FIX SPAMTRAP TO REPLY -=|
|=- So... your philosophy fits in a sig, does it? -=|
- 15
- JTabbedPane doesn't follow Sun's UI standard?
I'm using the JTabbedPane control.
While looking for a way to get rid of the line between the tabs and the
selected frame, I noticed that the Sun guidelines show that there shouldn't
be one there in the first place:
http://java.sun.com/products/jlf/ed2/book/HIG.Windows3.html#38176
Is this maybe a result of using the system L&F on MS windows?
Is there any way of changing this?
-Bella
|
|
|