Solution:

1. download activation.jar http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html or http://www.java2s.com/Code/Jar/GHI/Downloadactivationjar.htm

2. download mail.jar http://java.sun.com/products/javamail/downloads/index.html

3. add these two jar’s to the project

คู่มือการใช้ IP Msg


คู่มื่อการใช้ IP Msg

JavaScript String Replace All

The JavaScript function for String Replace replaces the first occurrence in the string. The function is similar to the php function str_replace and takes two simple parameters. The first parameter is the pattern to find and the second parameter is the string to replace the pattern with when found. The javascript function does not Replace All...



str = str.replace(”find”,”replace”)



To ReplaceAll you have to do it a little differently. To replace all occurrences in the string, use the g modifier like this:



str = str.replace(/find/g,”replace”)

การ Set Connection Timeout ใน Socket

มีสองตัวให้ Config น่ะครับ เป็น soTimeout ของ Socket อันนี้คือระยะเวลา Ideal ของ Socket ถ้าเกินก็จะ Timeout ออกไปต้อง Connect ใหม่ กับ ตอน socket.connect (InetSocketAddress, Timeout) อันนี้จะเป็น Timeout ของการรอตอบกลับค่าจาก External System ที่เราไปเรียก ซึ่ง ตามตัวอย่างข้างล่าง



InetSocketAddress socketAddr = new InetSocketAddress(url,port);
Socket socket = new Socket();
socket.connect(socketAddr,readTimeout);
socket.setSoTimeout(idealTimeout);



Often we need to create a (client) socket connection in java but we do not want to wait indefinitely for the connection to open. We need a way to timeout socket connections. Two solutions and recommended code.

Previously the only way was to create the socket in a Thread. And then kill the thread if it is running beyond a threshold time limit. This had two problems. First Thread.kill or Thread.suspend are deprecated methods and with good reason. Their availability cannot be ensured in future versions of Java. Secondly the process was clumsy to say the least. Now we have a better method since JDK 1.4.

java.net.Socket supports timeout from JDK1.4 onwards. The following is a sample code to enable socket timeout in Java. In this sample 500 milliseconds is chosen as timeout value.


// Open a socket without any parameters. It hasn’t been binded or connected
Socket sock = new Socket();

// Bind to a local ephemeral port
sock.bind(null);

// Connect to google.com on port 80 with a timeout of 500 milliseconds
sock.connect(new InetSocketAddress(”www.google.com”, 80), 500);

// Your code goes here

// Close the socket.
sock.close();
top