Programming/node.js2014. 9. 15. 18:21
$ yum install gcc gcc-c++
$ yum install openssl-devel make

$ wget http://nodejs.org/dist/v0.10.31/node-v0.10.31.tar.gz
※ http://nodejs.org/download/ 최신버젼받기

$ tar xvfz node-v0.10.31.tar.gz
$ cd node-v0.10.31

$ ./configure --prefix=/data/nodejs
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'clang': 0,
                 'gcc_version': 44,
                 'host_arch': 'x64',
                 'node_install_npm': 'true',
                 'node_prefix': '/data/nodejs',
                 'node_shared_cares': 'false',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_v8': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_unsafe_optimizations': 0,
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'node_use_systemtap': 'false',
                 'python': '/usr/bin/python',
                 'target_arch': 'x64',
                 'v8_enable_gdbjit': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_use_snapshot': 'true',
                 'want_separate_host_toolset': 0}}
creating  ./config.gypi
creating  ./config.mk

$ make && make install

##### bin Path는 계정 및 shell환경에 맞게 profile 에 등록하기##
$ vi /root/.bash_profile
PATH=$PATH:$HOME/bin
PATH=$PATH:/data/nodejs/bin ##nodjs bin등록
export PATH
source /root/.bash_profile
##############################################################

$ /data/nodejs/bin/node -v
v0.10.31


## npm 이용한 forever 데몬프로그램 설치########################
$ /data/nodejs/bin/npm install -g forever 

## npm 이용한 socket.io 설치###################################
$ /data/nodejs/bin/npm install -g socket.io


Posted by 시니^^
Programming/node.js2014. 9. 15. 15:49

Node.js 책 잠시 보고 만든 샘플입니다.

그냥 참고용으로!!ㅎㅎ


1. Server Side Node.js Socket.io

  1. var io = require('socket.io').listen(80);
  2. var clients = {};
  3. io.sockets.on('connection', function (socket){
  4. //입장 및 닉네임체크
  5. socket.on('create_nickname',function(nickname,returnFunction){
  6. //닉네임중복체크
  7. var returnCode = 1;
  8. for ( var i in clients ){
  9. if ( clients[i] == nickname ){
  10. returnCode = -1;
  11. break;
  12. }
  13. }
  14. //닉네임체크확인 결과 전달
  15. returnFunction(returnCode);
  16. //닉네임체크 유효화됨
  17. if ( returnCode == 1 ) {
  18. //클라이언트 닉네임등록
  19. clients[socket.id] = nickname;
  20. //새접속자로인한 전체 유저리스트 전달함
  21. io.sockets.emit('user_list',clients);
  22. //전체유저 메세지전송
  23. io.sockets.emit('msgPush',{"nickname":"시스템","msg":clients[socket.id]+" 유저가 입장하셨습니다."});
  24. console.log('CONNECT : ',nickname+' ['+socket.id+'] '+'('+Object.keys(clients).length+'명)');
  25. }
  26. });
  27. socket.on('msgSend',function(data){
  28. //자신을 제외한 전체유저에게 메세지전송
  29. socket.broadcast.emit('msgPush',data);
  30. /*
  31. *socket.emit('msgPush',data);//자신에게만 보낼때
  32. *socket.broadcast.emit('msgPush',data);//자신제외 전체유저
  33. *io.sockets.emit('msgPush',data);//자신포함 전체유저에게
  34. *io.sockets.in(socket_id).emit('msgPush',data);//특정유저에게 귓속말시 socket_id추가입력하면됨
  35.     *io.of('namespace').emit('msgPush', data); //of 지정된 name space의 유저
  36. */
  37. console.log('Chat Msg : ','['+data['nickname']+'] '+data['msg']);
  38. });
  39. //접속종료시처리
  40. socket.on('disconnect', function(){
  41. if ( clients[socket.id] ){
  42. //유저이탈 메세지전달
  43. io.sockets.emit('msgPush',{"nickname":"시스템","msg":clients[socket.id]+" 유저가 나가셨습니다."});
  44. console.log('DISCONNECT : ', clients[socket.id]);
  45. //이탈유저닉네임삭제
  46. delete clients[socket.id];
  47. //유저이탈 전체유저리스트 갱신
  48. io.sockets.emit('user_list',clients);
  49. }else{
  50. console.log('NOT USER DISCONNECT : ', socket.id);
  51. }
  52. });
  53. });


2. Client

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Chat</title>
  6. </head>
  7. <body>
  8. <div id="chatJoin">
  9. <form id="chatJoinForm">
  10. 대화명 : <input id="nickname" name="nickname" type="text"> <input type="submit" value="입장">
  11. </form>
  12. </div>
  13. <div id="chatRoom" style="display:none;">
  14. <div id="msgList" style="float:left;width:500px;height:300px;border:1px solid #1D365D;overflow:auto;"></div>
  15. <div style="float:left;width:100px;height:300px;border:1px solid #1D365D;margin-left:3px;">
  16. <div style="border-bottom:1px solid #1D365D;">접속자</div>
  17. <div id="userList"></div>
  18. </div>
  19. <div style="clear:both;">
  20. <form id="chatMsgForm">ChatMsg : <input id="msgText" name="msg" type="text"> <input type="submit" value="전송"></form>
  21. </div>
  22. </div>
  23. </body>
  24. <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
  25. <script type="text/javascript" src="socket.io.js"></script>
  26. <script type="text/javascript">
  27. $(function(){
  28. var socket;
  29. function createNickname(nickName){
  30. socket.emit('create_nickname',nickName,function(returnCode){
  31. if ( returnCode == 1 ){
  32. //정상적인 닉네임
  33. $('#chatJoin').hide();
  34. $('#chatRoom').show();
  35. $('#msgText').focus();
  36. }else{ //아니면 닉네임중복됨
  37. alert('존재하는 닉네임입니다.');
  38. $('#nickname').focus();
  39. socket.disconnect();
  40. }
  41. });
  42. }
  43. function msgAdd(data){
  44. var sHtml = '<div><span style="color:blue;">'+data['nickname']+'</span> : '+data['msg']+'</div>';
  45. $('#msgList').append(sHtml);
  46. $("#msgList").scrollTop($("#msgList")[0].scrollHeight);
  47. }
  48. $('#chatMsgForm').submit(function(event){
  49. event.preventDefault();
  50. var data = {"nickname":$('#nickname').val(),"msg":$('#msgText').val()}
  51. msgAdd(data);
  52. $('#msgText').val('');
  53. $('#msgText').focus();
  54. //서버에 입력메세지전달
  55. socket.emit('msgSend', data);
  56. });
  57. $('#chatJoinForm').submit(function(event){
  58. event.preventDefault();
  59. if ( !$('#nickname').val() ){
  60. alert("닉네임을 입력해주세요");
  61. $('#nickname').focus();
  62. return false;
  63. }
  64. /*
  65. *https://github.com/automattic/socket.io-client
  66. */
  67. socket = io.connect('http://127.0.0.1', {'forceNew':true,reconnection:false});
  68. socket.on('connect', function () {
  69. createNickname($('#nickname').val());
  70. });
  71. socket.on('user_list',function(clients){
  72. //심플테스트 버젼이라서 삭제하고 새로 갱신하는방안
  73. $('#userList').html('');
  74. for ( var i in clients ){
  75. if ( clients[i] == $('#nickname').val() ){
  76. sHtml = '<div style="font-weight:bold;">'+clients[i]+'</div>';
  77. }else{
  78. sHtml = '<div>'+clients[i]+'</div>';
  79. }
  80. $('#userList').append(sHtml);
  81. }
  82. });
  83. socket.on('msgPush',function(data){
  84. msgAdd(data);
  85. });
  86. socket.on('disconnect', function(){
  87. $('#msgList').html('');
  88. $('#nickname').val('');
  89. $('#chatJoin').show();
  90. $('#chatRoom').hide();
  91. alert('Server Disconnect');
  92. });
  93. socket.on('connect_error', function (data) {
  94. alert('CONNECT_ERROR : '+data);
  95. });
  96. });
  97. });
  98. </script>
  99. </html>


Posted by 시니^^
Programming/node.js2014. 9. 13. 11:44

메뉴얼 사이트

 - Application :  http://expressjs.com/api.html#express

 - Request : http://expressjs.com/api.html#req.params

 - Response :  http://expressjs.com/api.html#res.status

 - Router : http://expressjs.com/api.html#router

 - Middleware : http://expressjs.com/api.html#middleware.api


테스트 샘플자료 (자세한 내용은 위에 API 참조하면 방대함 정규식처리등 많음)

  1. var express = require('express'), http = require('http');
  2. var bodyParser = require('body-parser');
  3. var app = express();
  4. app.use(bodyParser());
  5. app.all('*', function( req, res, next){
  6. res.writeHead(200,{
  7. "Content-Type" : "text/plain"
  8. });
  9. next();
  10. });
  11. app.get("/", function( req, res){
  12. res.end("HOME DIR : /");
  13. });
  14. app.get("/test", function( req, res){
  15. res.end("HOME DIR : /test");
  16. });
  17. app.get("/params/:user", function( req, res){
  18. var sText = " Params : "+req.params.user; // OR req.param('user')
  19. sText += "\n GET : "+req.query.q; //search?q=test OR req.param('q')
  20. sText += "\n POST : "+req.param('name'); //POST name=tobi
  21. //sText += "Cookie : "+req.cookies.name; // Cookie: name=tj
  22. sText += "\n ip : "+req.ip; // req.ips When "trust proxy" is `true`, parse the "X-Forwarded-For"
  23. res.end(sText);
  24. });
  25. app.get("*", function( req, res){
  26. res.end("NOT PAGE");
  27. });
  28. http.createServer(app).listen(80, '127.0.0.1');
  29. console.log('HTTP URL : http://127.0.0.1:80/');


Posted by 시니^^
Programming/node.js2014. 9. 12. 16:42

자세한 내용은 메뉴얼 참조 http://nodejs.org/api/globals.html#globals_global


Global Objects

 - global

 - process

 - console

 - Class: Buffer

 - require()

 - require.resolve()

 - require.cache

 - require.extensions

 - __filename

 - __dirname

 - module

 - exports

 - setTimeout(cb, ms)

 - clearTimeout(t)

 - setInterval(cb, ms)

 - clearInterval(t)


변수류

__filename : 실행중인 경로포함 파일이름

__dirname : 실행중인 파일 경로까지만


실행한 Process 정보

 - http://nodejs.org/api/process.html#process_process_versions



Posted by 시니^^
Programming/JS/Jquery/Ajax2014. 9. 11. 12:05

jQuery Table Plugin 괜찮은 것 소개


메뉴얼 : http://mottie.github.io/tablesorter/docs/index.html


데모http://mottie.github.io/tablesorter/docs/index.html#Demo


tablesorter Bootstrap LESS theme 도 지원함


아래 샘플 보면 row 추가삭제에 대한 설명이나 페이징에 대한 설명도 잘 나와있다.

샘플설명자료http://mottie.github.io/tablesorter/docs/index.html#Examples


그리고 다양한 추가 플로그인 존재하여서 관리툴 개발시 상당히 유용함

Plugins / Widgets
 these widgets are included in the jquery.tablesorter.widgets.js file (except for extra filter formatter functions) 
 this widget is included with the plugin core.


Posted by 시니^^
Programming/PHP2014. 9. 4. 15:43


Anonymous functions - http://php.net/manual/ro/functions.anonymous.php


있다는 것만 알지.. 사용하지 않았다.. 

그런데 구글링 중 괜찮은 활용 방법을 찾아서!! 왠지 jquery 하는듯한 느낌은 뭐지...;;

 - 특정 배열값 파싱하거나 재구성할때 for문 안돌리고 array_map 이용할때 괜찮은듯함.

예) http://stackoverflow.com/questions/13435747/how-can-i-remove-the-file-extension-from-each-string-in-a-php-array


  1. <?php
  2. # your array
  3. $slike = array('1.jpg','253455.jpg','32.jpg','477.jpg');
  4. # if you have PHP >= 5.3, I'd use this
  5. $slike = array_map(function($e){
  6. return pathinfo($e, PATHINFO_FILENAME);
  7. }, $slike);
  8. # if you have PHP <= 5.2, use this
  9. $slike = array_map('pathinfo', $slike, array_fill(
  10. 0, count($slike), PATHINFO_FILENAME
  11. ));
  12. # dump
  13. print_r($slike);
  14. /*print
  15. Array
  16. (
  17. [0] => 1
  18. [1] => 253455
  19. [2] => 32
  20. [3] => 477
  21. )
  22. */
  23. ?>


※ 단 PHP 5.3 이상부터 가능함!

Posted by 시니^^
Programming/JS/Jquery/Ajax2014. 8. 21. 18:51

※ Jquery용 tablesorter 

http://mottie.github.io/tablesorter/docs/index.html


※ 설명가이드가 상당히 잘되어있음(페이징설명되어있음)

http://mottie.github.io/tablesorter/docs/index.html#Demo

http://mottie.github.io/tablesorter/docs/index.html#Examples


※ 부스트랩테마도 지원

http://mottie.github.io/tablesorter/docs/example-widget-bootstrap-theme.html


Posted by 시니^^
Programming/JAVA2014. 7. 31. 16:06

서버 환경

CentOS 6.5

TOMCAT 7

java version "1.7.0_55"


1. 간단하게 vi catalina.sh 또는 vi setenv.sh 설정함

----------------------------------------

CATALINA_OPTS="$CATALINA_OPTS

-Djava.rmi.server.hostname=xxx.xxx.xxx.xxx 

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=9080

-Dcom.sun.management.jmxremote.rmi.port=9081

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false"

----------------------------------------


2. 인증 방식 넣기 (설정시 access,password파일 추가등록)

------------------------------------------------

CATALINA_OPTS="$CATALINA_OPTS

-Djava.rmi.server.hostname=xxx.xxx.xxx.xxx 

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.port=9080

-Dcom.sun.management.jmxremote.rmi.port=9081

-Dcom.sun.management.jmxremote.authenticate=true

-Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access

-Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password

------------------------------------------------


※ 계정등록 ( 구글링해보니까 LDAP 연동 방법도 있는 듯 필요시 구글링해볼것!! )

https://code.google.com/p/tungsten-replicator/source/browse/trunk/commons/conf/sample.jmxremote.access?spec=svn1148&r=1148


vi jmxremote.access ( 계정에 맞게 readonly 또는 readwrite )

------------------------------------------------

admin readwrite \

      create javax.management.moitor.*,javax.management.timer.* \

      unregister

------------------------------------------------


vi jmxremote.password

------------------------------------------------

admin password

------------------------------------------------




3. 에러발생시 처리 방안

※ Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: dev-was01: dev-was01: Name or service not known

 => vi /etc/hosts 아래 host 추가하면됨

     127.0.0.1   localhost dev-was01

※ shutdown시 Error: Exception thrown by the agent : java.lang.NullPointerException

 => CATALINA_OPTS 아닌 JAVA_OPTS 에 넣으면 Exception 에러발생


※ catalina-jmx-remote.jar 필요시 톰캣사이트에서 다운르도 후 lib폴더에 넣기!

 => http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.53/bin/extras/




4. Apache 메뉴얼 listener was configured in server.xml 추가하는 방법


URL : http://tomcat.apache.org/tomcat-7.0-doc/config/listeners.html

AttributeDescription
rmiRegistryPortPlatform

The port to be used by the JMX/RMI registry for the Platform MBeans. This replaces the use of thecom.sun.management.jmxremote.port system property that should not be set when using this listener.

rmiServerPortPlatform

The port to be used by the Platform JMX/RMI server.

rmiBindAddress

The address of the interface to be used by JMX/RMI server. This option is incompatible with setting the system propertycom.sun.management.jmxremote.ssl to true.

useLocalPorts

Should any clients using these ports be forced to use local ports to connect to the the JMX/RMI server. This is useful when tunnelling connections over SSH or similar. Defaults to false.

Using file-based Authentication and Authorisation

If this listener was configured in server.xml as:

  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
          rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

with the following system properties set (e.g. in setenv.sh):

  -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password
  -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access
  -Dcom.sun.management.jmxremote.ssl=false

$CATALINA_BASE/conf/jmxremote.password containing:

admin letmein

$CATALINA_BASE/conf/jmxremote.access containing:

admin readwrite

then opening ports 10001 (RMI Registry) and 10002 (JMX/RMI Server) in your firewall would enable jconsole to connect to a Tomcat instance running behind a firewall using a connection string of the form:

service:jmx:rmi://<hostname>:10002/jndi/rmi://<hostname>:10001/jmxrmi

with a user name of admin and a password of letmein.



Posted by 시니^^
Programming/JAVA2014. 6. 25. 14:27

개발후 배포시 war로 압축해서 배포하는 그때


서버환경(개발/운영)에 따라서 DB접근 정보나 기타 cfg 설정이 다른 경우가 있다


그런 경우 PropertyPlaceholderConfigurer등 설정 정보를 다르게 보게 해야되는 데


구글링 해보니까 아래 Stackoverflow 몇가지를 제시하고있다. 


http://stackoverflow.com/questions/11735526/spring-loading-application-properties-based-on-tomcat-servlet-contect-definition


그중에 괜찮다고 생각되는 두가지 방안


1. 아래 방법처림 배포될 서버에 예상해서 설정해서 여러개로 구성하는 방법

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:your-production-config.properties</value>
            <value>file:C:/Users/${user.name}/test-application.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>        
</bean>


2. ${catalina.home} 변수 이용한 Tomcat 디렉토리의 conf에 설정을 따로 구성해두는 방안

<context:property-placeholder location="file:${catalina.home}/conf/myFirst.properties" ignore-unresolvable="true" />
<context:property-placeholder   location="classpath:second.properties"  ignore-unresolvable="true"  />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
    <value>file:${catalina.home}/conf/dbpool.properties</value>
</property>
</bean>


개발환경에서 한개 서버에 버젼에 따라서 여러 톰캣을 띄워야 할 경우에는 2번 방법이 괜찮은 것 같다.

Posted by 시니^^
Programming/JAVA2014. 6. 24. 11:56

form / Ajax 통해서 URL or Get 데이터 encodeURIComponent 보낼때에


한글이 제대로 인코딩이 안된다고하면


web.xml에 아래 해당 filter 정보를 입력해준다


그리고 filter-name의 정보를 해당 url pattern에 mapping 해주면된다 servlet에 따라서 mapping 해줄것!!

일반적으로 전체가 다 UTF-8 환경이라면 /* 하면될듯하다.


  
    encodingFilterUTF8
    org.springframework.web.filter.CharacterEncodingFilter 
    
        encoding
        UTF-8
    
  
  
    encodingFilterUTF8
    /*
  
  
Posted by 시니^^