DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    2

    java.net.SocketException problem

    What im trying to do is to create a client and server system similar to the whois protocol.

    What i have is a server program that has a database of peoples locations. Then the client can query the server by giving it a users username and it will respond with there location.

    Ive not really used any of java's networking features before doing this so i appologise if any of my questions are trivial.

    I have the client program working as it should, but im haveing problems with the server.

    Here is a bit of the code i have:
    Code:
    	public static void run() throws Exception
    	{
    		int port = 43;
    
    		try 
    		{
    			ServerSocket acceptSocket;
    			acceptSocket = new ServerSocket(port) ;
    			while (true) 
    			{
    				Socket s = acceptSocket.accept() ;
    				host = s.getInetAddress().getHostName();
    				doRequest(s);
    				s.close();
    			}
    		} 
    		catch (IOException e) 
    		{
    			System.out.println("run Method Error: " + e.toString());
    		}
    	}
    That is what waits for the connections on port 43, that again seems to work ok.

    This next bit of code however keeps throwing java.net.SocketException's:
    Code:
    	// reads the request from the stream
    	public static void readRequest(Socket s) throws Exception
    	{
    		int c;
    
    		System.out.println("Doing request");
    
    
    		InputStream in = s.getInputStream();
    		try
    		{
    
    			while ((c = in.read()) != -1) 
    			{
    				System.out.print((char) c);
    				request = request + (char)c;
    			}
    			in.close();
    
    		}
    		catch (IOException e)
    		{
    			System.out.println("readRequest Error: " + e.toString());
    		}
    
    	}
    The full exception is: java.net.SocketException: Connection reset by peer: JVM_
    recv in socket input stream read

    The data from the client is being received correctly, so why is this error being generated?

    Thanks in advance,

    Adam.

  2. #2
    Join Date
    Jan 2005
    Location
    Limerick, Ireland
    Posts
    19
    Connection reset by peer means that the other client application closed the connection post the code for the client

  3. #3
    Join Date
    Jan 2005
    Posts
    2
    Thanks for the reply but i have sorted the problem now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links