wpearsall
Feb 9th, 2004, 06:59 PM
OK... I have got a socket i need to read text on...
the bufferedreader is calling "in", and socket "wskSocket".
//Take steps to conect to the server
synchronized boolean connectToServer()
{
if( connected == true ) {
disconnectFromServer();
}
connected=false;
try
{
InetAddress addr = InetAddress.getByName( serverAddress );
wskSocket = new Socket( addr,serverSocketNumber );
}
catch( UnknownHostException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" failed to find server host!",
"Host Lookup Error",JOptionPane.ERROR_MESSAGE );
return false;
}
catch( IOException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" failed to connect to the server!","Socket Error",JOptionPane.ERROR_MESSAGE );
return false;
}
try
{
in = new BufferedReader(new InputStreamReader(wskSocket.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(wskSocket.getOutputStream()));
}
catch( IOException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" cannot create data stream!\n\n"+
"Closing client...","Data Stream Error",
JOptionPane.ERROR_MESSAGE );
try
{
wskSocket.close();
}
catch( IOException io_e )
{
}
return false;
}
connected = true;
thListen = new ListenToIncoming();
thListen.start();
System.out.println("OK: Returning True....");
return true;
}
private class ListenToIncoming extends Thread{
public void run(){
System.out.println("ITS RUNNING!!!!");
System.out.println("Sending Login Info...");
String sMsgToSend;
sMsgToSend=" ## +DL : "+ UserName+" : "+
Password+" : "+sAppVer;
SendData( sMsgToSend );
try{
String sIn;
while ((sIn = in.readLine()) != null) {
System.out.println( sIn );
CheckIncoming( sIn );
}
System.out.println( "OK... WE JUST SKIPPED THE ENTIRE DATA PROCESSING!!!!" );
}catch( IOException e ){
System.out.println( "We Got An Error...." );
}
}
}
for some reason, IT DOES NOT READ INCOMING TEXT!!!!
it creates the new thread, and starts it running properly, but it wont read it...
i have got this output on my "System" ....
OK: Returning True....
ITS RUNNING!!!!
Sending Login Info...
even tho text arrives at the server ok..
[i know this because its all comin ok on ma server log]
10/02/2004 00:59:46: Connection requested from 127.0.0.1:2021;
10/02/2004 00:59:46: Checking Login [Client Version: x.xx] (Connection: 96);
10/02/2004 00:59:47: -> Login = False [Invalid Password For: wpearsall] (Connection: 96);
it doesnt recieve the reply from the server [well, doesnt "read" it anyhow...]
Does anyone know wot can b the problem w/ the above code?
I have even tried sending data from the server directly... but not got read either
: shrugs :
All help is VERY appreciated...
thanks.
Wayne
the bufferedreader is calling "in", and socket "wskSocket".
//Take steps to conect to the server
synchronized boolean connectToServer()
{
if( connected == true ) {
disconnectFromServer();
}
connected=false;
try
{
InetAddress addr = InetAddress.getByName( serverAddress );
wskSocket = new Socket( addr,serverSocketNumber );
}
catch( UnknownHostException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" failed to find server host!",
"Host Lookup Error",JOptionPane.ERROR_MESSAGE );
return false;
}
catch( IOException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" failed to connect to the server!","Socket Error",JOptionPane.ERROR_MESSAGE );
return false;
}
try
{
in = new BufferedReader(new InputStreamReader(wskSocket.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(wskSocket.getOutputStream()));
}
catch( IOException e )
{
JOptionPane.showMessageDialog(window,"Error: "+sAppTitle+
" cannot create data stream!\n\n"+
"Closing client...","Data Stream Error",
JOptionPane.ERROR_MESSAGE );
try
{
wskSocket.close();
}
catch( IOException io_e )
{
}
return false;
}
connected = true;
thListen = new ListenToIncoming();
thListen.start();
System.out.println("OK: Returning True....");
return true;
}
private class ListenToIncoming extends Thread{
public void run(){
System.out.println("ITS RUNNING!!!!");
System.out.println("Sending Login Info...");
String sMsgToSend;
sMsgToSend=" ## +DL : "+ UserName+" : "+
Password+" : "+sAppVer;
SendData( sMsgToSend );
try{
String sIn;
while ((sIn = in.readLine()) != null) {
System.out.println( sIn );
CheckIncoming( sIn );
}
System.out.println( "OK... WE JUST SKIPPED THE ENTIRE DATA PROCESSING!!!!" );
}catch( IOException e ){
System.out.println( "We Got An Error...." );
}
}
}
for some reason, IT DOES NOT READ INCOMING TEXT!!!!
it creates the new thread, and starts it running properly, but it wont read it...
i have got this output on my "System" ....
OK: Returning True....
ITS RUNNING!!!!
Sending Login Info...
even tho text arrives at the server ok..
[i know this because its all comin ok on ma server log]
10/02/2004 00:59:46: Connection requested from 127.0.0.1:2021;
10/02/2004 00:59:46: Checking Login [Client Version: x.xx] (Connection: 96);
10/02/2004 00:59:47: -> Login = False [Invalid Password For: wpearsall] (Connection: 96);
it doesnt recieve the reply from the server [well, doesnt "read" it anyhow...]
Does anyone know wot can b the problem w/ the above code?
I have even tried sending data from the server directly... but not got read either
: shrugs :
All help is VERY appreciated...
thanks.
Wayne