Ady Wicaksono Daily Activities

Archive for July 15th, 2007

Public Land Mobile Network

leave a comment »

Cellular telecommunication is a big bussiness today. Big bussiness means big money :). OK, I don’t want to talk about bussiness today. I just want to share about how researcher design the network for this cellular telecommunication. Here’s:

PLMN Network

User use mobile station (SIMCard + Mobile Phone) {ps. I’m not talking about CDMA}.

Operator provide everything behind: BSC, BTS, MSC, SMSC, HLR, ….

I hope that image is descriptive enough, at least for myself 😀

Advertisements

Written by adywicaksono

July 15, 2007 at 4:45 pm

Posted in Telco - GSM

SSL Connection with Java

with one comment

Here is an example Java code to create SSL connection between you and HTTPS
(taken from http://www.cafeaulait.org/slides/iw2000/whatsnew/04.html)

import java.net.*;
import java.io.*;
import java.security.*;
import javax.net.ssl.*;

public class HTTPSClient {
	public static void main(String[] args) {
		if (args.length == 0) {
			System.out.println("Usage: java HTTPSClient host");
			return;
		}

		int port = 443; // default https port
		String host = args[0];

		try{
			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
			SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

			SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

			Writer out = new OutputStreamWriter(socket.getOutputStream());
			// https requires the full URL in the GET line
			out.write("GET / HTTP/1.0\\r\\\n");
			out.write("\\r\\n");
			out.flush();

			// read response
			BufferedReader in = new BufferedReader(
						new InputStreamReader(socket.getInputStream()));
			int c;
			while ((c = in.read()) != -1) {
				System.out.write(c);
			}

			out.close();
			in.close();
			socket.close();
		}catch (IOException e) {
			System.err.println(e);
		}
	}
}

You can compile & run it:

$ javac HTTPSClient.java
$ java HTTPSClient login.yahoo.com

But wait, if HTTPS server give you certificate which is signed by “unknown” Certificate Authority ( I mean not signed by approved CA like Thawte, Verisign) then you will get this error

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

or something like it

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

However, I found the fast solutions (I forget where was it, but I started from Google)
so all certificates (signed and unsigned) become accepted and the exception disappears.
Of course this is not recommended for a production system but quite useful for testing :).

import java.net.*;
import java.io.*;
import java.security.*;
import javax.net.ssl.*;

public class HTTPSClient {
	public static void main(String[] args) {
		if (args.length == 0) {
		   System.out.println("Usage: java HTTPSClient host");
		   return;
		}

		int port = 443; // default https port
		String host = args[0];

		
		TrustManager[] trustAll = new javax.net.ssl.TrustManager[]{
		  new javax.net.ssl.X509TrustManager(){
			  public java.security.cert.X509Certificate[] getAcceptedIssuers(){
				return null;
			  }
			  public void checkClientTrusted(java.security.cert.X509Certificate[] certs,String authType){}
			  public void checkServerTrusted(java.security.cert.X509Certificate[] certs,String authType){}
		  }
		};
		
		try {
		
			javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
			sc.init(null, trustAll, new java.security.SecureRandom());
		
			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
			SSLSocketFactory factory = (SSLSocketFactory) sc.getSocketFactory();
			SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

			Writer out = new OutputStreamWriter(socket.getOutputStream());
			out.write("GET / HTTP/1.0\\r\\n");
			out.write("\\r\\n");
			out.flush();

			// read response
			BufferedReader in = new BufferedReader(
			new InputStreamReader(socket.getInputStream()));
			int c;
			while ((c = in.read()) != -1) {
				System.out.write(c);
			}
			out.close();
			in.close();
			socket.close();
		}catch (Exception e) {
			System.err.println(e);
		}
	}
}

Written by adywicaksono

July 15, 2007 at 4:20 pm

C code to test thread limitation on Linux

with 5 comments

Still remember with posting about thread limitation on Linux?

Here’s a C code to test it..

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

#define MAX_THREADS 10000
int i;

void run(void) {
   char c;
   if (i < 10)
      printf("Address of c = %u KB\n", (unsigned int) &c / 1024);
   sleep(60 * 60);
}

int main(int argc, char *argv[]) {
   int rc = 0;
   pthread_t thread[MAX_THREADS];
   printf("Creating threads ...\n");
   for (i = 0; i < MAX_THREADS && rc == 0; i++) {
     rc = pthread_create(&(thread[i]), NULL, (void *) &run, NULL);
     if (rc == 0) {
       pthread_detach(thread[i]);
       if ((i + 1) % 100 == 0)
         printf("%i threads so far ...\n", i + 1);
     }
     else
        printf("Failed with return code %i creating thread %i.\n",rc, i + 1);
   }
   exit(0);
}

Save it as threadlimit.c and compile it with

gcc -lpthread -o resulttest threadlimit.c

You have an exe file => “resulttest” so execute it now

./resulttest

Here is an example as result of this C code execution on my Fedora 🙂
Linux 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 i686 i386 GNU/Linux

# ulimit -s
10240

# ./resulttest
Creating threads ...
100 threads so far ...
200 threads so far ...
300 threads so far ...
Failed with return code 12 creating thread 304.

Boom!!!, I only create 303 threads. No try decrease thread stack size to 100

# ulimit -s 100
100

# ./resulttest
Creating threads ...
100 threads so far ...
200 threads so far ...
300 threads so far ...
400 threads so far ...
500 threads so far ...
600 threads so far ...
700 threads so far ...
800 threads so far ...
900 threads so far ...
1000 threads so far ...
1100 threads so far ...
1200 threads so far ...
1300 threads so far ...
1400 threads so far ...
1500 threads so far ...
....
10000 threads so far...
... [CTRL-C]

Wow, I could create a lot of threads :D….

Written by adywicaksono

July 15, 2007 at 3:35 pm

Posted in Linux, Programming

My first time in Singapore

with 2 comments

May 15, 2007 -> Yes, this is my first time in Singapore & my first time abroad. Thanks to my friend Mr. Catur. which help me, took me from Changi Airport, give a temporary place to stay (at Kembangan), give a lot information about Singapore.

After a week, finally God, Allah SWT, introduce me to another good guy in Singapore, his name is Abdi (from Bandung Institut of Technology), he offered me to join him in a common room on his flat at Ubi Avenue. I agreed and I stayed for around 1,5 months with cheap rent fee but good facility (TV Cable, Internet, PUB included). How cheap is it? Hmmm…. it’s a secret 😀

Now, I move to another place at 25 Hillview Avenue, Glendale Park. Live with 2 others Indonesian Professional (Willim & Jasson Lin). Hey, Jasson is a kind & professional property agent, I recommended him for helping you find a good property in Singapore :). Just contact me with your requirement and I will introduce you to him 😀

Here’s my place taken from Google Earth

Glendale Park Condo

Written by adywicaksono

July 15, 2007 at 2:56 pm

Posted in life