• Post Reply Bookmark Topic Watch Topic
  • New Topic

remote server closing connection  RSS feed

 
Abdul Basit
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a problem, when i try to communicate with finger protocol . Basically finger service closing connection when it answer my request and when i do second request with same socket so it do nothing. I check it out through �ethereal� that what is happening in tcp stream so basically after full fill my first request finger service send �RST� packet which is basically for connection close. So finger service is closing connection but i tried many method to some how find it out that remote server has close my connection but no success. So any one from you guide me how i can find out that remote server has close my connection.

Sample code is here :

import java.net.*;
import java.util.*;
import java.io.*;
public class DemoFinger{

public static void main(String[]args) throws Exception
{

Socket soc = new Socket("192.168.1.18",79) ; // opening socket
InputStream input = soc.getInputStream();
PrintWriter prWri = new PrintWriter(soc.getOutputStream(), true);
// soc.setSoTimeout(10000); // setting socket time-out


for(int j=0;j<2;j++)
{
prWri.println("kk") ;

/*I have to put some thing here to find out server socket still listenning or not */

int first = input.read() ;
int max = input.available() ;
int[] fromSocket = new int[max] ;

Vector fromSock = new Vector() ;
int m = 0 ;
while ( (m = input.read()) != -1) { //max != 0 &&

Integer intgr = new Integer(m) ; //only obj can be stored in vector
fromSock.addElement(new Character( (char) intgr.intValue())) ;
//max = input.available() ;
}

char[] fromSocketChars = new char[fromSock.size()] ;

for (int z = 0 ; z < fromSocketChars.length ; z++) {
fromSocketChars[z] = ( (Character) (fromSock.elementAt(z))). charValue() ;
}

String response = new String(fromSocketChars) ;
response = (char) first + response ;

System.out.println(response);
}
}

}
 
Joe Ess
Bartender
Posts: 9414
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the Finger protocol document, RFC 1196:

A TCP connection is opened to a remote host on the Finger port. An RUIP [Remote User Information Program] becomes available on the remote end of the connection to process the request. The RUIP is sent a one line query based upon the Finger query specification. The RUIP processes the query, returns an answer, then closes the connection normally.

So the Finger daemon is operating as specified and closing your connection. If you want to perform another query, create another connection.
 
Abdul Basit
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe.
yeh u right finger closing my connection and now i am making connection for next request but the problem is i want to use same code for telnet, ftp and other services , that is why it is really necessary for me to find out before sending any query on wire that connection is still alive or not.
I think that there should be a way to find out that remote server has been close your connection.
Regards
MABASIT
 
Joe Ess
Bartender
Posts: 9414
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean like the Socket.isConnected() and Socket.isClosed() methods?
 
Abdul Basit
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Joe,
exactly like Socket.isConnected() and Socket.isClosed().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!