I have a Java Class that does some low level message sending over TCP/IP, my
first message should include a username and password, the second message I
send should contain the token_id returned from the first request, this is all
fine,
but they are saying that I do not make the second request with the token_id
over
the same connection.
Personally I do not see how it cannot be over the same connection, because I
only call the closeConnection() method once I am done, and if the connection
was not open anymore then I would receive an error when sending the second
message.
I've had people who said it might be CF or Java cleaning up after me and
closing
the connection, but again I do not believe this is it.
Anyone any ideas? Following is the (relevant) code that makes the call.
Socket = createObject( "java", "CFTransportLayer" ).init( "114.25.41.78", 5498
);
response = Socket.send( message );
*** process response and get token_id here etc. etc.
responseOverflow = Socket.send( message );
Socket.closeConnection();
***********************
The java code is as following:
import java.io.*;
import java.net.*;
public class CFTransportLayer
{
Socket Socket = null;
PrintWriter out = null;
BufferedReader in = null;
String returnContent = "";
public CFTransportLayer ( String host, int port )
throws Exception
{
try
{
// Create the socket
Socket = new Socket( host, port );
System.out.println( "Socket connection
established.\n" );
out = new PrintWriter(
Socket.getOutputStream(), true );
System.out.println( "Writer to remote
socket created.\n" );
in = new BufferedReader( new
InputStreamReader(Socket.getInputStream() ) );
System.out.println( "Reader from remote
socket created.\n" );
}
catch ( UnknownHostException e )
{
System.out.println( "Unknown host.\n" );
}
catch ( IOException e )
{
System.out.println( "I/O Exception.\n" );
}
catch ( Exception e )
{
System.out.println( "An exception has occurred, error message:
"
+ e.getMessage() + "\n" );
}
}
public String send ( String message )
{
// Send data over socket
out.println( message );
System.out.println( "Message sent to remote
server.\n" );
out.flush();
System.out.println( "Text from remote server about to
be read.\n" );
try
{
// The header is the first 36 characters
of the message
char[] myHeader = new char[ 36 ];
// Read the first 36 characters
in.read( myHeader, 0, 36 );
System.out.println( "Converting the header to a string.\n" );
// Convert the header array to a string
String header = new String( myHeader );
returnContent = header;
System.out.println( "Outputting the header: " + header + ".\n" );
// Get the string that holds the message length
String byteToReadString = header.substring( 28, 36 );
System.out.println( "Getting the message length: " +
byteToReadString
+ ".\n" );
System.out.println( "Parsing the string.\n" );
// Parse the string to an integer
int byteToRead = Integer.parseInt( byteToReadString );
char[] myMessage = new char[ byteToRead ];
System.out.println( "Reading the rest of the message.\n" );
// Try and read the message
try
{
int remaining = byteToRead;
// Loop untill all bytes are read
while ( remaining > 0 )
{
remaining -= in.read( myMessage, byteToRead -
remaining, remaining );
}
}
catch ( Exception e )
{
System.out.println( "Error reading the rest of the message,
byteToRead: " + byteToRead + ". message: " + e.getMessage() + "\n" );
}
// Convert the message array to a string
String messageString = new String( myMessage );
System.out.println( "Outputting the message " + messageString +
".\n" );
System.out.println( messageString );
// Concatenate the header and message content
returnContent = returnContent + messageString;
}
catch ( IOException e )
{
System.out.println( "The read from the socket " +
Socket.getPort()
+ " terminated unexpectedly, error message: " + e.getMessage() + "\n" );
}
// return result
return returnContent;
}
public void closeConnection ()
throws IOException
{
try
{
in.close();
out.close();
// close socket
Socket.close();
}
catch ( IOException e )
{
System.out.println( "Error trying to close the socket" +
e.getMessage() + "\n" );
}
}
public boolean isConnected ()
{
return Socket.isConnected();
}
public boolean isClosed ()
{
return Socket.isClosed();
}
public boolean isInputShutdown ()
{
return Socket.isInputShutdown();
}
public boolean isOutputShutdown ()
{
return Socket.isOutputShutdown();
}
}
________________________________
Taco Fleur - E-commerce Development Manager
Shelco Searches & Services
An Authorised ASIC Information Broker
www.shelco.com.au
Ph: + 61 7 3236 2605
---
You are currently subscribed to cfaussie as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/