Re: How to close ServerSocket

2000-05-14 Thread Chris Abbey

ok,  I'll go out on a limb and guess that you're trying for multi-threaded
access/shutdown here... where thread A creates the socket saves a reference
to it somewhere and then goes into accept and you're trying to shut it down
with another thread.

without putting some code to handle shutdown behind your accpet loop logic
you're going to take interrupted exceptions from accpet and/or io exceptions
from close...



thread A (accept loop) :
do {
ss.accept();
//handle connection,
//must also tolerate
//close w/o data
} while (! global.shutdown )



thread B (shutdown thread) :
global.shutdown = true;
sock = new Socket("127.0.0.1", myPort);
sock.close(); //force loop to itterate.



final class global {
static transient boolean shutdow = false;
}

  cabbey at home dot net <*> http://members.home.net/cabbey
   I want a binary interface to the brain!
Today's opto-mechanical digital interfaces are just too slow!


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




unsubscribe

2000-05-14 Thread Anson Wong




 


Re: How to close ServerSocket

2000-05-14 Thread Ashish

hi

the code i posted is not actual code

actually ss.close is part of a function which i am calling on certain
condition
as far as ss.accpet call it is working perfectly

i am using jdk1.2.2 on windows NT and jdk1.2.2RC4 on linux

ashish

- Original Message -
From: "Albert Y. C. Lai" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 14, 2000 8:39 PM
Subject: Re: How to close ServerSocket


> "Ashish" <[EMAIL PROTECTED]> writes:
>
> > how to close server socket without throwing an exception?
> >
> > if i call close then it throws exception which gets caught in catch 1
not in catch 2
> > can anybody explain
>
> I tried it on JDK 1.1.7v3.  First, I did not get any exception that
> you got.  Second, the program does not even go as far as the
> ss.close() statement: it blocks at ss.accept() (which is correct
> behaviour).  If I then have a client connect to the port this program
> is listening to, then the program continues and runs to completion
> without exception.
>
> In other words, I cannot reproduce your result.
>
> Complete program I used:
>
> import java.io.*;
> import java.net.*;
>
> public class SS
> {
>   public static void main(String args[]) {
> ServerSocket ss = null;
> try
>   {
> ss = new ServerSocket(3856);
>   }
> catch (Exception e)
>   {
> System.out.println("0");
>   }
>
> try
>   {
> ss.accept();
>   }
> catch(Exception e) /* 1 */
>   {
> System.out.println("1");
>   }
>
> try
>   {
> ss.close();
>   }
> catch(Exception e) /* 2 */
>   {
> System.out.println("2");
>   }
>   }
> }
>
> --
> [If you post a response, no need to cc me; if you cc me, please say so.]
> A compiler always tells the truth and calls a spade a spade.
>
>
> --
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>
>


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




Re: How can I connect to MySQL using JDBC

2000-05-14 Thread javor

hi

i setup s MySQL server and connected to it a few days ago so i'm not
experienced SQLer too :) 
here is how i connect to the server: 

 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
 Connection C =
DriverManager.getConnection("jdbc:mysql://localhost/hop?user=root&password=my_pass");
 /* here i'm connecting to server at localhost, database name is hop,
with user root and password my_pass */

 //after that i do something like 
 Statement s = C.createStatement();
 s.execute("insert into loki values('holms', '324')");

you can see i'm using mm.mysql driver (it's type 4 too). It's GPL'ed too :) 
There is a link to the mm.mysql driver somewhere on the mysql.com. This is the
only driver i've used but maybe i'll try twz1jdbcForMysql too. Is it free(i
mean GPL or something like that)?

hope that helps
javor

On Thu, 19 Jun 2036, Rakesh Raveendran wrote:
> Hi,
> 
>I am using a type 4 driver for connecting to MySQL database.The Class
> file(driver file) is being detected, but I am not able to connect to the
> database.There are no exceptions being thrown stating that connection is not
> being created.Can any body send me some sample code as to how to connect. Iam
> using twz1jdbcForMysql driver.
> 
> regards,
> Rakesh  
> 
> 
> Get free email and a permanent address at http://www.netaddress.com/?N=1
> 
> 
> --
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




Re: How to close ServerSocket

2000-05-14 Thread Albert Y. C. Lai

"Ashish" <[EMAIL PROTECTED]> writes:

> how to close server socket without throwing an exception?
> 
> if i call close then it throws exception which gets caught in catch 1 not in catch 2
> can anybody explain

I tried it on JDK 1.1.7v3.  First, I did not get any exception that
you got.  Second, the program does not even go as far as the
ss.close() statement: it blocks at ss.accept() (which is correct
behaviour).  If I then have a client connect to the port this program
is listening to, then the program continues and runs to completion
without exception.

In other words, I cannot reproduce your result.

Complete program I used:

import java.io.*;
import java.net.*;

public class SS
{
  public static void main(String args[]) {
ServerSocket ss = null;
try
  {
ss = new ServerSocket(3856);
  }
catch (Exception e)
  {
System.out.println("0");
  }

try
  {
ss.accept();
  }
catch(Exception e) /* 1 */
  {
System.out.println("1");
  }

try
  {
ss.close();
  }
catch(Exception e) /* 2 */
  {
System.out.println("2");
  }
  }
}

-- 
[If you post a response, no need to cc me; if you cc me, please say so.]
A compiler always tells the truth and calls a spade a spade.


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]