2010년 11월 16일 화요일

열린포트 확인하는 방법

시스템 명령어인 netstat 를 사용하는 방법

#netstat -nap (열려 있는 모든 포트)
#netstat -l 또는 netstat -nap | grep LISTEN (LISTEN 되는 모든 포트)
#netstat -nap | grep ESTABLISHED | wc -l ( 모든 서비스 동시 접속자 수)
#netstat -nap | grep :80 | grep ESTABLISHED | wc -l ( 웹 동시 접속자 수)


포트스캔 명령어로 확인 하는 방법

# TCP 포트 확인 방법
nmap -sT -p 1-65535 localhost
# UDP 포트 확인 방법
nmap -sU -p 1-65535 localhost
# 네트워크에 열린 포트 확인
nmap -sX -p 22,53,110 211.239.111.*


lsof 명령어로 확인 방법

# 모든 네트워크 소켓 확인
lsof -I

tomcat 여러개의 포트 사용하기

톰캣에서도 MS의 IIS와 같이 포트 번호에 따라 호스팅하는 것이 가능하다.(근데 웨케힘드노)

TOMCAT_HOME\conf\server.xml 을 열고 아래와 같이 Service 엘리먼트를 추가한다.

아래 좋은 블로그가 있어서 펌해왔다. ^__^) b
 아파치와 연동없이 톰캣만으로도 하나의 IP로 다수의 웹사이트를 운영하는 것이 가능하다.
(아파치와 톰캣을 연동하는 방법에 대해서는 차후에 자세히 올리도록 하겠다)

특히 개발자의 경우 여러개의 프로젝트를 개발하거나 테스트하고자 할 때 웹사이트를 여러개 운영해야한다. 다수의 웹 사이트를 세팅하는 방법은 크게 2가지가 있다.
가상호스트를 이용하는 방법은 도메인을 이용하여 실제로 서비스를 운영하는 경우가 아니면 개발자에겐 별 의미가 없다. 여기서는 두번째 방법인 IP 어드레스의 포트를 이용하는 방법에 대해서 설명하겠다. (바로가기 : 톰캣에서 가상 호스트를 이용하는 방법)
우선 설치 환경은 다음과 같다.
  • O/S : Windows XP (난 아직 리눅스를 잘 모른다. 비슷하겠지만 테스트해보지 않았다)
  • Tomcat 6.0 (정확히는 6.0.10) : 다운로드
설명의 편의를 위해 톰캣의 설치 디렉토리는 'TOMCAT_HOME' 으로 표기할 것이다. 참고로 내 경우는 C:\Server\Tomcat6.0 이다.

설정하는 방법은 간단하다. /TOMCAT_HOME/conf/에 있는 server.xml 파일만 수정하면 끝이다. server.xml의 쓸데없는 주석부분을 다 없애고 핵심부분만 남겨놓으면 아래와 같다.

<Service name="Catalina">
  <Connector port="8080" protocol="HTTP/1.1"
   maxThreads="150" connectionTimeout="20000"
   redirectPort="8443" />
  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  <Engine name="Catalina" defaultHost="localhost">
   <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    resourceName="UserDatabase"/>

   <Host name="localhost"  appBase="webapps"    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
   </Host>

  </Engine>
 </Service>


우선 빨간색으로 표시한 부분만 이해하고 넘어가도 상관없다.
Connector port="8080"은 HTTP로 넘어오는 포트를 지정하는 것이다. 톰캣의 기본 포트가 8080인 이유가 여기에 있다. 따라서 8080 대신 기본 80포트를 사용하고 싶다면? 바로 이 부분을 port="80"으로 바꾸어주면 된다.

다 음, Host 지시어의 appBase="webapps" 는 웹어플리케이션(웹사이트)의 위치를 나타낸다. appBase="./webapps"와 같은 의미다. 실제 위치는 TOMCAT_HOME/webapps이다. 물론 "d:/weapps/myweb1" 과 같이 절대경로로 지정하는 것도 가능하다.

그럼 웹사이트를 하다 더 추가하고 싶다면? 위의 <Service>...</Service>를 하나 더 만들어 버리면 된다. 위의 코드를 복사한 다음 server.xml 에 추가한다. 그리고 빨간색으로 표시한 부분만 수정하자.
<Service name="Catalina2">
  <Connector port="9090" protocol="HTTP/1.1"
     maxThreads="150" connectionTimeout="20000"
     redirectPort="8443" />
  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
 
  <Engine name="Catalina" defaultHost="localhost">
   <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
     resourceName="UserDatabase"/>

   <Host name="localhost"  appBase="d:/webapps/myweb2"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
   </Host>
  </Engine>
 </Service>

다른 웹어플리케이션을 돌리기 위해 서비스를 하나 더 추가한 것이다.
port="9090" 은 새로 추가하고 싶은 포트이다.
appBase="d:/webapps/myweb2"는 9090 포트에서 돌아갈 웹사이트 위치이다.

이제 server.xml 설정은 끝난 것이다.
마지막으로 웹사이트의 ROOT 디렉토리를 지정해주자. 아래의 폴더를 생성한다.

d:/webapps/myweb2/ROOT/   (
d:/webapps/myweb2/ROOT/WEB-INF/
(WEB-INF 폴더를 만들고 web.xml 파일을 추가한다. 그냥 /TOMCAT_HOME/webapps/ROOT/WEB-INF/에 있는 web.xml 을 복사하면 된다.

무지 간단하다. 하지만 난 이 간단한 것을 위해서 하루종일 삽질해야만 했다. 검색해 보아도 문서는 많은데 실제 도움이 될만한 것이 별로 없었다.

테스트하기 위해 ROOT/index.html 또는 index.jsp를 만든다.
이제 톰캣을 재시작하고 웹브라우저로 접속해 보자.
http://localhost:8080
http://localhost:9090

2010년 11월 15일 월요일

Unix 명령어

파일의 겟수를 체크할 경우
ls -l |wc -l
(예시)
nsdiap2:tmax [/app/tcpor/webapps.bak/WEB-INF/lib]# ls -l /app/tcpor/webapps/WEB*/lib |wc -l

2010년 11월 11일 목요일

크롬 에러시 조치 방법

\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" --no-sandbox --new-http

no-sandbox --new-http

을 단축키에 추가해준다

2010년 11월 4일 목요일

FireBug Tips and Tricks

FireBug Tips and Tricks

There is so much power packed into this little FireFox plug-in. It is truly a revolutionary tool for web developers. Here is a quick and dirty set of its most powerful features.
To get started, open up firebug using F12 or by clicking its icon in the lower right corner of FireFox. To jump straight to the console and start typing commands you can use the Ctrl+Shift+L keyboard shortcut.

From here you can type commands. Try entering document. This will bring up the document DOM object and you can click on that link to get to the DOM and inspect all of the properties of the document object. A shortcut is also available by typing inspect(document) etc. You can use $ and $$ as in Prototype, such as $(‘firebug’) and inspect($$(‘.firebug’)). Use the up and down arrows to cycle through command history.
  • Use console.log and sprintf formatting commands for debugging.
  • Use console.info, console.warn and console.error to set your debugging levels.
  • Use console.time to log the time your functions take to run.
  • Use the error console to view the stack trace of the errors.
You can download Firebug Lite to make these methods work in Internet Explorer. I recommend that you remove your console commands before you go live.
Try Console logging test using console.log You can use sprintf formatting here.
function consoleIntro(){
 var x = "fubar";
 var y = 543;
 console.log("value of x is %s and value of y is %d", x, y);
}
Try Console Error Levels console.info|warn|error
function consoleLogLevels(){
 var a = "This is an info level message";
 var b = "This is a warn level message";
 var c = "This is an error level message";
 console.info(a);
 console.warn(b);
 console.error(c);
}
Try Timer logging console.time|timeEnd
function timeThisTask(){
 console.time("Sample Timer");
 for(x=100000;x>0;x--){}
 console.timeEnd("Sample Timer");
}
Try Error Stack Traces to see stack trace of the errors
function stack1(){
 var d = "fu";var e = "bar";var f = stack2(d,e)
 console.log(f);
}
function stack2(d,e){return stack3(d,e);}
function stack3(d,e){return UndefinedVariable;}

Use the debugger to add breakpoints, debug JavaScript code and step through your code.
There are 3 ways to trigger the debugger:
  1. Use the debugger command.
  2. Add a breakpoint by clicking on the line number
  3. Enable the “Break on All Errors” option for the Script tab.
Try a Deubgger Demo using the debugger command
function debugMe(){
 debugger;
 var g = 1;
 var h = new Date().getMilliseconds();
 while(g < 100){
  g *= 10;
  h -= g;
 }
}


Use the profiler to record detailed statistics on your Script calls and DOM events. This works very much like macros. To manually start profiling click on the profile button in the Console tab. Then try performing some actions on the page. When you are done click on the profile button again. A report is returned which captures the funtions that were called within that time period.
The report output data can be sorted. Own Time tells you how much time each function call took in milliseconds and as a percentage of the total time which can be useful in finding bottlenecks in your code.
Try Manual Profiler test using the manual profile feature
function profileMe(){
 timeThisTask();
 var timerlink = document.getElementById("tabs").
       getElementsByTagName('li')[2].firstChild;
 var typeNode = timerlink.nodeType;
 var nameNode = timerlink.nodeName;
 var valuNode = timerlink.nodeValue;
}
You can also add profilers to your code via the console.profile(“foo”) – console.profileEnd(“foo”) function calls. This can be great when you want to track down events that happen onload.
Try the Coded Profiler using console.profile|profileEnd command
function profiledFunction(){
 console.profile("Test Auto Profiler");
 timeThisTask();
 profileMe();
 console.profileEnd("Test Auto Profiler");
}

You can log calls to a specific function call and see what parameters are being passed to it and how many times it is being called. To do this open the script tab, find your function and right click within it. From the popup menu choose the “log calls to “function name”".

Now whenever that function is called you get a nice message in the console along with the parameter values sent to it.
Try the Logged Function test with logged functions
function callLoggedFunction(){
 for(x=0;x<2;x++){for(y=1;y>0;y--){loggedFuction(x,y);}}
}
function loggedFuction(x,y){
 if(y>x) console.info("y is greater than x");
}

In the HTML tab you can also log events for specific elements. This can be useful when you are creating elements on the fly via the DOM and want to track all the events happening behind the scenes.
The Net tab is quite useful for tracing HTTP request and responses. Network traffic can be filtered by type (HTML, CSS, JS, Images, XmlHttpRequest). The Params tab is very handy and shows you the request parameters in a table format. This is great for tracing your Ajax requests. The issue with this that I found is that once a request is made which leaves the current page you loose the previous pages net events. Maybe a feature for the next version of FireBug?

From the HTML tab you can use the Layout tab to view and edit any element’s offset, margin, border, padding and dimension values on the fly.
In the Style sub tab of the HTML tab you can choose an option to “Show Computed Style” which shows you the final style values of the selected HTML element. Another neat trick is that you can click on any CSS property and edit it inline in real time. You can use the up/down keys and page up/page down keys to change numeric values and see your changes in real time, for example padding etc.

2010년 11월 1일 월요일

Sharing Fonts in ActionScript 3.0 - Part 1: Creating a Font SWF

Sharing Fonts in ActionScript 3.0 - Part 1: Creating a Font SWF

By: Robert Reinhardt

In this tutorial series, you learn how to use the new Font class in ActionScript 3.0 and Flash Player 9. The Font class enables you to embed one or more fonts in a Flash movie (SWF file), and reuse the font with other SWF files. In this tutorial, you learn how to create a font SWF file and load it into another Flash movie.
NOTE: In order to follow along with the tutorials in this series, you need to use Adobe Flash CS3 Professional. The font sharing techniques discussed in this series require ActionScript 3.0 and Flash Player 9.

Developing a font sharing strategy

Before you embark on building a reusable system of font SWF files, you should carefully consider how you will implement the fonts in your Flash project. You have several options for structuring your font data in a SWF file:
  • Individual font and font style: You can embed one font (and only one style for that font) per font SWF file, and build a library of individual font SWF files. For example, if your Flash project needs BlurMedium, Big Caslon Bold, and Myriad Pro, you would create three Flash files (ActionScript 3.0). Each Flash file's library would contain only one font symbol. The benefit to this approach is that the file size of each font SWF should be rather small, enabling a shorter load time into other SWF files that require the font(s). You would also avoid loading font data that wasn't being utilized by other SWF files--for example, if you're project only required Verdana in Normal style, and your font SWF contains Verdana, Verdana Bold and Verdana Italic, the latter two styles are soaking up file size (and causing a longer download time) even though they're not being used by the project. Another benefit to this approach is that you can develop a large catalog of font SWFs that you can reuse from project to project. The drawback to this approach is that you'll need to manage more font SWF files.
  • Multiple fonts and/or font styles: You could also opt to build a Flash file (ActionScript 3.0) that contains multiple font symbols. The font SWF file would contain more data, and would require a longer download time into other SWF files. However, if you need to use several fonts in a movie, downloading one font SWF file may be easier to manage than downloading multiple font SWF files.
You also need to determine how you will name your font asset(s) in your font SWF files. You can use either of the following approaches:
  • Use the font's name: If you want an easy system to maintain, simply name each font symbol after the font's name and style. For example, if you want to add BlurMedium Bold to your font SWF file, name the font symbol and font class BlurMediumBold.
  • Create a name based on style: You can develop a font SWF that contains font symbols named after a style usage, enabling you to change specific font faces and styles without needing to update the font name used in other SWF files. For example, you could create a font symbol whose class name is BodyFont and set its font choice to Verdana. In your other SWF files that require the BodyFont style, you can refer to the term BodyFont instead of Verdana. In this way, should you ever need to change the font choice for the BodyFont symbol, you don't need to update your ActionScript code.
In this tutorial series, you learn how to use both naming structures. The first three tutorials will use the former approach, naming each font symbol directly after the font's name.

Creating and Registering a Font Symbol

Some of the steps to build an ActionScript 3.0 (AS3) font SWF are identical to those used to create shared fonts in runtime shared libraries (RSL's) available in previous versions of the Flash Player. (You can still use RSL's in Flash Player 9 as well.) Perform the following steps to create an AS3 font SWF for the common typeface, Verdana.
  1. Open Flash CS3, and create a new Flash file (ActionScript 3.0). Save this file as Verdana.fla.
  2. Open the Library panel (Ctrl/Cmd+L). Click this panel's options menu in the top right corner and choose New Font. In the Font Symbol Properties dialog, choose Verdana in the Font menu. In the Name field, type Verdana as shown in Figure 1. Click OK.
    Figure 1 - The Font Symbol Properties dialog
  3. Right-click (or Ctrl+click on Mac) the Verdana font symbol in the Library panel, and choose Linkage. In the Linkage Properties dialog (Figure 2), select the Export for ActionScript check box. By doing so, the Export in first frame option is automatically selected as well. In the Class field, type Verdana. Now, the Verdana symbol is officially an ActionScript 3.0 class that you can use in your AS3 code. Click OK.
    Figure 2 - The Linkage Properties dialog
  4. In the Timeline window, rename Layer 1 to actions.
  5. Select frame 1 of the actions layer, and open the Actions panel (F9, or Option+F9 on Mac). Add the code shown in the following code block. The Font.registerFont() method enables you to make a font symbol available to any other SWF file that loads the SWF file containing the Verdana symbol.
    import flash.text.Font;

    Font.registerFont(Verdana);
  6. Save the Flash file, and test the movie (Ctrl/Cmd+Enter). The font SWF will not create anything on the stage, but the font is embedded in the SWF file. You can open the Bandwidth Profiler (View > Bandwidth Profiler) in the Test Movie environment to see that the SWF file is 19 KB, the size of the embedded Verdana font.

Loading the Font SWF into Another Flash movie

After you've created an AS3 font SWF file, you're ready to test the font by loading the SWF into another Flash movie. In this section, you create a tester that loads the font SWF and shows the name of the embedded font in the Output panel. Complete the following steps to load the font SWF file ito another Flash movie:
  1. In Flash CS3, create a new Flash file (ActionScript 3.0). Save this file as font_tester.fla. Save this file in the same location as the Verdanda.swf file created in the last section.
  2. Rename Layer 1 to actions. Select frame 1 of the actions layer, and open the Actions panel (F9, or Option+F9 on Mac). Add the code shown in the following code block. This code create a new Loader instance to grab the Verdana.swf created in the last section. When the SWF has finished the loading, the Font.enumerateFonts() method is used to list all of the embedded fonts available to use in the Flash movie.
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.net.URLRequest;
    import flash.events.Event;

    var fontLoader:Loader = new Loader();
    var fontLoaderInfo:LoaderInfo = fontLoader.contentLoaderInfo;

    fontLoaderInfo.addEventListener(Event.COMPLETE, onFontLoaded);

    fontLoader.load(new URLRequest("Verdana.swf"));

    function onFontLoaded (e:Event):void {
       var info:LoaderInfo = e.currentTarget as LoaderInfo;
       var loader:Loader = info.content as Loader;
       var embeddedFonts:Array = Font.enumerateFonts(false);
       for(var i:Number = 0; i < embeddedFonts.length; i++){
          var item:Font = embeddedFonts[i];
          trace("[" + i + "] name:" + item.fontName + ", style: " + item.fontStyle + ", type: " + item.fontType);
       }
    }
  3. Save the Flash file, and test the Flash movie (Ctrl/Cmd+Enter). Once the Verdana.swf file loads into the font_tester.swf file, the onFontLoaded() function is invoked. The Output panel in Flash CS3 should show the following message:
    [0] name:Verdana, style: regular, type: embedded

Conclusion

You now know how to build an AS3 font SWF and load it into another Flash movie with ActionScript 3.0 code. In the next tutorial of this series, you learn how create a text field which displays text using an embedded font symbol from another SWF file.