------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------

아래와 같은 간단한 채팅 (NodeJS + SocketIO)에서 시작해서 Bootstrap + MySQL + MongoDB등을 사용하도록 소스를 계속 수정 합니다. 

GitHub에서는 version별로 다운로드를 받으면 단계별로 구현된 부분을 볼 수도 있습니다.


<목적 & 방향>

- 1차적으로 그룹단위의 웹 채팅으로 동시 접속 1,000명을 지원 합니다.

- 기본적인 간편 가입 절차를 제공 하며, RDBMS를 사용합니다.

- 초대를 통해서 참여를 하기 위한 채팅 Key를 생성하고 이를 통해서 인증합니다.

- HA(High Availability)를 위해서 메시지 저장과 복구를 위해 NoSQL( Not Only SQL )를 사용합니다.

- Scale-Out를 제공하기 위해서, IO Slave와 Master로 구성을 합니다.





<기본설명>

NodeJs_SocketIO_PartOne

Just simple your webChat v 0.0.1

This is a simple web chat through nodeJS & socket.io.

이 예제는 간단하게 웹채팅을 nodeJS와 socket.io를 통해서 구현했다.

New things

This added some features from orginal. First can select a userid and message can scroll, but can't not delete message.

이 예제는 원래자료를 참고해서 수정이 되었다. 첫째로 유저아이디를 선택하고, 메시지는 화면 스크롤이되지만, 메시지를 화면내에서 삭제하지는 않는다.


<프로그램 소스>

https://github.com/sketchout/NodeJs_SocketIO_PartOne


<실행화면 v1>





<실행화면 v2>





<실행화면 v3>








PgAdmin 서버 리스트...

pgAdminIII의 서버 연결 정보를 많이 등록을 해 놓은 상태에서 새로운 PC로 옮겨야 할때등은

다시 등록을 하려니 너무 오래 걸릴것 같아서, 당황 스럽다.

위와 경우도 있지만, 혹시나 만일의 사태(삭제등)을 대비해서...


pgAdmin III의 서버 연결 정보를 백업하고 복구 하자.



1. Regedit에서 저장된 정보를 export(내보내기)를 실행한다. save.reg로 저장을 한다.

    위치 : HKEY_CURRENT_USER\SOFTWARE\pgAdmin III

2. save.reg 파일을 복사나 이동후에 실행 한다.


스트레스 <끝>


좋은자료 - Eclipse에서 Maven을 활용해서 Dynamic Web Project 만들기 


[원제] How to Create Dynamic Web Project using Maven in Eclipse?

[주소] http://crunfy.me/14KewSX



Step-1

Create a simple maven Project in Eclipse.


Step-2

Select default Workspace location

Step-3

Select the maven archetype as: maven-archetype-webapp and click on next.


Step-4

Fill out below details and click Finish. This step creates Maven Project in your Eclipse Environment.

Step-5

If you see error “The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path index.jsp /CrunchifyMavenTutorial/src/main/webapp” then add below maven dependency.

add Apache Tomcat to your Targeted Runtimes.

Step-6

Your Maven Project should look like this.

Step-7

Now build project with “Maven Clean Install” to check there isn’t any dependency issue with project. 

Step-8

Deploy Application on Apache Tomcat Server.

Step-9

Visit http://localhost:8080/CrunchifyMavenTutorial/index.jsp to see your result.

'0.일반개발' 카테고리의 다른 글

NodeJs_SocketIO_PartOne  (1) 2016.04.21
PGAdmin 서버 연결 정보 추출  (0) 2016.03.15
mongoDB  (0) 2015.12.16
node.js를 centos 7에 설치하는 방법  (0) 2015.12.03
60초안에 리눅스 성능 분석하기  (0) 2015.12.03


1,사용자 계정 관리

-몽고DB를 시동하고 나서 가장 먼저 해야 할 일은 데이터베이스에 접근할 수 있도록 사용자를 추가하는 것이다.



1) 계정 생성

use test
db.createUser( {use: "testUser", 
    pwd: "test", 
    roles: ["readWrite", "dbAdmin"] } )

2) 계정 삭제

use test
db.dropUser("testUser")


3) 계정 목록

use admin
show users

사용자 계정은 각 데이터베이스의 db.system.users 컬렉션에 저장된다.


참조 : https://mylko72.gitbooks.io/node-js/content/chapter12/chapter12_2.html


명령어 : http://www.tutorialspoint.com/mongodb/mongodb_create_database.htm

How To Install Node.js on a CentOS 7 server

-node.js를 centos 7에 설치하는 방법


원문 : https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-a-centos-7-server


Introduction

Node.js is a Javascript platform for server-side programming. It allows users to easily create networked applications that

require backend functionality.  (Node.js는 서버쪽 프로그래밍을 위한 자스스크립트 플랫폼이다. 이것을 개발자에게 백엔드

기능을 갖춘 네트웍 처리를 하는 어플리케이션을 만들기 쉽게 해준다.)

By using Javascript as both the client and server language, development can be fast and consistent.

(클라이언트와 서버 언어 양쪽을 자바스크립트를 사용하는 것은 개발은 빠르고 일관성있게 해 준다.)


In this guide, we will show you a few different ways of getting Node.js installed on a CentOS 7 server so that you can get started.

(이 가이드에서는, CentOS 7 서버에  Node.js를 얻는 몇가지 방안을 보여주고 시작할 수 있게 해 줄 것이다.)

Most users will want to use the EPEL installation instructions or the NVM installation steps.

(대부분의 사용자는 EPEL 설치 방식과 NVM 설치 절차를 사용하는 것을 원할 것 같다.)


1. Install Node from Source

One way of acquiring Node.js is to obtain the source code and compile it yourself.

To do so, you should grab the source code from the project's website. On the downloads page,

right click on the "Source Code" link and click "Copy link address" or whatever similar option your browser gives you.


>wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz

>tar xzvf node-v* && cd node-v*

>sudo yum install gcc gcc-c++

>./configure
>make

>sudo make install

>node --version


2. Install a Package from the Node Site

Another option for installing Node.js on your server is to simply get the pre-built packages

from the Node.js website and install them.


cd ~
wget http://nodejs.org/dist/v0.10.30/node-v0.10.30-linux-x64.tar.gz


3. Install Node from the EPEL Repository

An alternative installation method uses the EPEL (Extra Packages for Enterprise Linux) repository

that is available for CentOS and related distributions.


>sudo yum install epel-release

>sudo yum install nodejs

>node --version

v0.10.30


4. Install Node Using the Node Version Manager

Another way of installing Node.js that is particularly flexible is through NVM, the Node version manager.

This piece of software allows you to install and maintain many different independent versions of Node.js,

and their associated Node packages, at the same time.


>curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh

>curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash

>nvm list-remote


Conclusion

As you can see, there are quite a few different ways of getting Node.js up and running on your CentOS 7 server.

~


+ MongoDB


1.CentOS에 MongoDB 64bit 설치하기 , http://yakolla.tistory.com/55

yum 저장소 추가

1
2
3
4
5
6
$ vi /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

yum으로 설치

1
$ yum -y install mongodb-org

yum -update로 몽고디비가 업데이트되는 것을 방지

1
2
$ vi /etc/yum.conf
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

실행시키기

1
2
3
4
5
6
$ service mongod start
$ service mongod restart
$ service mongod stop
 
# 부팅시 자동으로 실행하려면
$ chkconfig mongod on

방화벽 오픈

1
2
3
$ iptables -I INPUT 1 -p tcp --dport 27017 -j ACCEPT
$ service iptables save
$ service iptables restart


2.Install MongoDB on Red Hat Enterprise or CentOS Linux
 
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/


* httpd / 리눅스 아파치 설치 (yum)

http://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_%EC%95%84%ED%8C%8C%EC%B9%98_%EC%84%A4%EC%B9%98_(yum) 


* Deprecated Linux networking commands and their replacements

https://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ 

Deprecated command

Replacement command(s)

arpip n (ip neighbor)
ifconfigip a (ip addr), ip linkip -s (ip -stats)
iptunnelip tunnel
iwconfigiw
nameifip linkifrename
netstatssip route (for netstat-r), ip -s link (for netstat -i), ip maddr (for netstat-g)
routeip r (ip route)


[Linux] CentOS 7 / RHEL 7에 redis 설치 하기

http://blog.box.kr/?p=675


Node.js 에서 Redis 사용하기


http://mydreamisthebestcooder.tistory.com/7

1.  Redis 모듈 설치하기.


 $ npm install connect-redis

 $ npm install redis


* node.js 에서 socket.io 사용하기


http://forum.falinux.com/zbxe/index.php?document_srl=573508&mid=lecture_tip


>npm install socket.io

리눅스 서버에 성능 문제로 접속을 한다면, 최초 1분안에 어떤 부분을 체크 하나요?

You login to a Linux server with a performance issue: what do you check in the first minute?


시스템 리소스 사용량의 정도와 실행중인 프로그램을 아래 10개의 명령어를 통해서 정보를 얻을 수 

있다.

uptime
dmesg | tail
vmstat 1
mpstat -P ALL 1
pidstat 1
iostat -xz 1
free -m
sar -n DEV 1
sar -n TCP,ETCP 1
top


1. uptime

$ uptime
 23:51:26 up 21:31,  1 user,  load average: 30.02, 26.43, 19.02

This is a quick way to view the load averages, which indicate the number of tasks (processes) wanting to run.


2. dmesg | tail

$ dmesg | tail
[1880957.563150] perl invoked oom-killer: gfp_mask=0x280da, order=0, oom_score_adj=0
[...]
[1880957.563400] Out of memory: Kill process 18694 (perl) score 246 or sacrifice child
[1880957.563408] Killed process 18694 (perl) total-vm:1972392kB, anon-rss:1953348kB, file-rss:0kB
[2320864.954447] TCP: Possible SYN flooding on port 7001. Dropping request.  Check SNMP counters.

This views the last 10 system messages, if there are any.

3. vmstat 1

$ vmstat 1
procs ---------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
34  0    0 200889792  73708 591828    0    0     0     5    6   10 96  1  3  0  0
32  0    0 200889920  73708 591860    0    0     0   592 13284 4282 98  1  1  0  0
32  0    0 200890112  73708 591860    0    0     0     0 9501 2154 99  1  0  0  0
32  0    0 200889568  73712 591856    0    0     0    48 11900 2459 99  0  0  0  0
32  0    0 200890208  73712 591860    0    0     0     0 15898 4840 98  1  1  0  0
^C

Short for virtual memory stat, vmstat(8) is a commonly available tool (first created for BSD decades ago).

4. mpstat -P ALL 1

$ mpstat -P ALL 1
Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015  _x86_64_ (32 CPU)

07:38:49 PM  CPU   %usr  %nice   %sys %iowait   %irq  %soft  %steal  %guest  %gnice  %idle
07:38:50 PM  all  98.47   0.00   0.75    0.00   0.00   0.00    0.00    0.00    0.00   0.78
07:38:50 PM    0  96.04   0.00   2.97    0.00   0.00   0.00    0.00    0.00    0.00   0.99
07:38:50 PM    1  97.00   0.00   1.00    0.00   0.00   0.00    0.00    0.00    0.00   2.00
07:38:50 PM    2  98.00   0.00   1.00    0.00   0.00   0.00    0.00    0.00    0.00   1.00
07:38:50 PM    3  96.97   0.00   0.00    0.00   0.00   0.00    0.00    0.00    0.00   3.03
[...]

This command prints CPU time breakdowns per CPU, which can be used to check for an imbalance.

5. pidstat 1

$ pidstat 1
Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015    _x86_64_    (32 CPU)

07:41:02 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
07:41:03 PM     0         9    0.00    0.94    0.00    0.94     1  rcuos/0
07:41:03 PM     0      4214    5.66    5.66    0.00   11.32    15  mesos-slave
07:41:03 PM     0      4354    0.94    0.94    0.00    1.89     8  java
07:41:03 PM     0      6521 1596.23    1.89    0.00 1598.11    27  java
07:41:03 PM     0      6564 1571.70    7.55    0.00 1579.25    28  java
07:41:03 PM 60004     60154    0.94    4.72    0.00    5.66     9  pidstat

07:41:03 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
07:41:04 PM     0      4214    6.00    2.00    0.00    8.00    15  mesos-slave
07:41:04 PM     0      6521 1590.00    1.00    0.00 1591.00    27  java
07:41:04 PM     0      6564 1573.00   10.00    0.00 1583.00    28  java
07:41:04 PM   108      6718    1.00    0.00    0.00    1.00     0  snmp-pass
07:41:04 PM 60004     60154    1.00    4.00    0.00    5.00     9  pidstat
^C

Pidstat is a little like top’s per-process summary, but prints a rolling summary instead of clearing the screen.


6. iostat -xz 1

$ iostat -xz 1
Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015  _x86_64_ (32 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          73.96    0.00    3.73    0.03    0.06   22.21

Device:   rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
xvda        0.00     0.23    0.21    0.18     4.52     2.08    34.37     0.00    9.98   13.80    5.42   2.44   0.09
xvdb        0.01     0.00    1.02    8.94   127.97   598.53   145.79     0.00    0.43    1.78    0.28   0.25   0.25
xvdc        0.01     0.00    1.02    8.86   127.79   595.94   146.50     0.00    0.45    1.82    0.30   0.27   0.26
dm-0        0.00     0.00    0.69    2.32    10.47    31.69    28.01     0.01    3.23    0.71    3.98   0.13   0.04
dm-1        0.00     0.00    0.00    0.94     0.01     3.78     8.00     0.33  345.84    0.04  346.81   0.01   0.00
dm-2        0.00     0.00    0.09    0.07     1.35     0.36    22.50     0.00    2.55    0.23    5.62   1.78   0.03
[...]
^C

This is a great tool for understanding block devices (disks), both the workload applied and the resulting performance.

7. free -m

$ free -m
             total       used       free     shared    buffers     cached
Mem:        245998      24545     221453         83         59        541
-/+ buffers/cache:      23944     222053
Swap:            0          0          0

The right two columns show:

  • buffers: For the buffer cache, used for block device I/O.
  • cached: For the page cache, used by file systems.

8. sar -n DEV 1

$ sar -n DEV 1
Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015     _x86_64_    (32 CPU)

12:16:48 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:16:49 AM      eth0  18763.00   5032.00  20686.42    478.30      0.00      0.00      0.00      0.00
12:16:49 AM        lo     14.00     14.00      1.36      1.36      0.00      0.00      0.00      0.00
12:16:49 AM   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

12:16:49 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:16:50 AM      eth0  19763.00   5101.00  21999.10    482.56      0.00      0.00      0.00      0.00
12:16:50 AM        lo     20.00     20.00      3.25      3.25      0.00      0.00      0.00      0.00
12:16:50 AM   docker0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
^C
Use this tool to check network interface throughput: rxkB/s and txkB/s, as a measure of workload, and also to check if any limit has been reached.

9. sar -n TCP,ETCP 1

$ sar -n TCP,ETCP 1
Linux 3.13.0-49-generic (titanclusters-xxxxx)  07/14/2015    _x86_64_    (32 CPU)

12:17:19 AM  active/s passive/s    iseg/s    oseg/s
12:17:20 AM      1.00      0.00  10233.00  18846.00

12:17:19 AM  atmptf/s  estres/s retrans/s isegerr/s   orsts/s
12:17:20 AM      0.00      0.00      0.00      0.00      0.00

12:17:20 AM  active/s passive/s    iseg/s    oseg/s
12:17:21 AM      1.00      0.00   8359.00   6039.00

12:17:20 AM  atmptf/s  estres/s retrans/s isegerr/s   orsts/s
12:17:21 AM      0.00      0.00      0.00      0.00      0.00
^C
This is a summarized view of some key TCP metrics. These include:
  • active/s: Number of locally-initiated TCP connections per second (e.g., via connect()).
  • passive/s: Number of remotely-initiated TCP connections per second (e.g., via accept()).
  • retrans/s: Number of TCP retransmits per second.
 

10. top

$ top
top - 00:15:40 up 21:56,  1 user,  load average: 31.09, 29.87, 29.92
Tasks: 871 total,   1 running, 868 sleeping,   0 stopped,   2 zombie
%Cpu(s): 96.8 us,  0.4 sy,  0.0 ni,  2.7 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:  25190241+total, 24921688 used, 22698073+free,    60448 buffers
KiB Swap:        0 total,        0 used,        0 free.   554208 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 20248 root      20   0  0.227t 0.012t  18748 S  3090  5.2  29812:58 java
  4213 root      20   0 2722544  64640  44232 S  23.5  0.0 233:35.37 mesos-slave
 66128 titancl+  20   0   24344   2332   1172 R   1.0  0.0   0:00.07 top
  5235 root      20   0 38.227g 547004  49996 S   0.7  0.2   2:02.74 java
  4299 root      20   0 20.015g 2.682g  16836 S   0.3  1.1  33:14.42 java
     1 root      20   0   33620   2920   1496 S   0.0  0.0   0:03.82 init
     2 root      20   0       0      0      0 S   0.0  0.0   0:00.02 kthreadd
     3 root      20   0       0      0      0 S   0.0  0.0   0:05.35 ksoftirqd/0
     5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H
     6 root      20   0       0      0      0 S   0.0  0.0   0:06.94 kworker/u256:0
     8 root      20   0       0      0      0 S   0.0  0.0   2:38.05 rcu_sched
The top command includes many of the metrics we checked earlier. It can be handy to run it to see if anything looks wildly different from the earlier commands, which would indicate that load is variable.



 


 



원문 : http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html?spref=fb&m=1

'0.일반개발' 카테고리의 다른 글

mongoDB  (0) 2015.12.16
node.js를 centos 7에 설치하는 방법  (0) 2015.12.03
Visual Studio 2010 프로젝트 속성 페이지  (0) 2015.12.03
$LogFile ( NTFS 볼륨 로그 )  (0) 2015.12.01
GPS 좌표 얻기  (0) 2015.11.25

* Visual Studio 2010 프로젝트 속성 페이지 

<원래 구성>
구성속성 : ( 솔루션폴더/Debug/실행파일 )
    일반
        출력디렉토리     : $(SolutionDir)$(Configuration)\
        
        대상이름        : $(ProjectName)


구성속성 :( 컴파일후 실행 )
    디버깅
        명령        : $(TargetPath)
                        = $(SolutionDir)$(Configuration)\$(ProjectName)
        작업디렉토리    : $(ProjectDir)


* 명령         : 실행될 파일의 경로 및 파일명

* 작업디렉토리    : 실행파일이 실행되는 위치


Q : 출력디렉토리와 대상이름을 변경시 컴파일 후에 실행되지 않는다.

A : 위치 변경하기 ( $(SolutionDir) -> $(ProjectDir)Run\ ) 
ex) 프로젝트 Debug폴더와 같은 위치에 Run폴더를 만들고, 참조하는 DLL과 리소스파일을 복사하고, 
exe 파일을 컴파일시 출력하도록 한다.

<수정 사항>
구성속성 : ( 솔루션폴더/Debug/실행파일 )
    일반
        출력디렉토리     : $(ProjectDir)Run\

구성속성 :( 컴파일후 실행 )
    디버깅
        작업디렉토리    : $(OutDir)
                        == 출력디렉토리





'0.일반개발' 카테고리의 다른 글

node.js를 centos 7에 설치하는 방법  (0) 2015.12.03
60초안에 리눅스 성능 분석하기  (0) 2015.12.03
$LogFile ( NTFS 볼륨 로그 )  (0) 2015.12.01
GPS 좌표 얻기  (0) 2015.11.25
Eclipse Workingset  (0) 2015.11.18

$LogFile이란? NTFS 트랜젝션 로그 파일

  -시스템 오류나 갑작스런 전원 차단 발생시, 작업 중이던 파일 복구를 위해 사용

  -모든 트랜젝션 작업을 레코드 단위로 기록 ( 파일생성, 삭제등 )

  -각 작업 레크드는 고유의 LSN을 가짐

  -복구를 위해 각 레코드는 작업 데이터와 작업 전 테이터를 가짐

  -각 볼륨마다 하나씩 존재

  -MFT엔트리 번호2에 존재




관련 문서 다운로드 : A Dig into the $LogFile

INSIGHT_A-Dig-into-the-LogFile.pdf


blueangel

blueangel1275@gmail.com

http://blueangel-forensic-note.tistory.com

자료 링크 : https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwjI64vRyrnJAhXDj5QKHeX0D1gQFggnMAE&url=http%3A%2F%2Fforensicinsight.org%2Fwp-content%2Fuploads%2F2012%2F05%2FINSIGHT_A-Dig-into-the-LogFile.pdf&usg=AFQjCNH09ydE-_NeK5eIHDij43UcFV-LjQ&sig2=ysSnoG7WVYwg9zlyD1dA2A

'0.일반개발' 카테고리의 다른 글

60초안에 리눅스 성능 분석하기  (0) 2015.12.03
Visual Studio 2010 프로젝트 속성 페이지  (0) 2015.12.03
GPS 좌표 얻기  (0) 2015.11.25
Eclipse Workingset  (0) 2015.11.18
IBM BlueMix  (0) 2015.11.17
안드로이드에서 구글Map을 불러오고, GPS좌표를 표현하는 방식
  - 안드로이드 버젼 : 2.x
  1. MapActivity만들기


 
public class Map2 extends MapActivity {
//---------------------
 /** Called when the activity is first created. */
//---------------------
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 }
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private void initVar()
{
 textView.setText("시작="); // 상단 텍스트 영역
 textView2.setText("시작=..."); // 하단 텍스트 영역
lat=0.0d; // latitude
 lng=0.0d; // longitude
 acc=""; // 정확도
 pro=""; // 좌표 정보 제공자
 gps_status="2";
 addressString = "...";
fine=0; // 0 : GPS 1: Network
}
}
2. main.xml 수정 ( ui.png ) -l (지도 apiKey는 구글 발급 사이트를 통해서 ) – 화면 구성 입니다. // 개인 pc key값에 의해 MapKey가 만들어 집니다.








3.OnCreate() 설정 -– 텍스트 출력 창 설정 / 버튼 설정 [ GPS 로그 보기는 제외 합니다. ]
//---------------------
 /** Called when the activity is first created. */
//---------------------
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 mContext = this;
 //---------------------
 // 텍스트 : 현재위치 주소
 //---------------------
 linearLayout = (LinearLayout) findViewById(R.id.textview);
textView = new TextView(this);
 textView.setTextColor(Color.BLUE);
 textView.setGravity(Gravity.CENTER);
 //textView.setText(addressString);
 linearLayout.addView(textView);

//---------------------
 // 텍스트 : 상태 정보
 //---------------------
 linearLayout2 = (LinearLayout) findViewById(R.id.textview2);
 textView2 = new TextView(this);
 textView2.setTextColor(Color.BLUE);
 textView2.setGravity(Gravity.BOTTOM);
 linearLayout2.addView(textView2);
//---------------------
 // 지도 불러오기
 //---------------------
initMap();
 //---------------------
 // 재시작 버튼
 //---------------------
 btnUpdate = (Button)findViewById(R.id.Button01);
//-----------------------------------
 // GPS 좌표 얻기
 //---------------------
btnUpdate.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
runGPS(); // GPS 가동 시키기
}
 });
//---------------------
 // 재시작 버튼
 //---------------------
 btnList = (Button)findViewById(R.id.Button02);
//-----------------------------------
 // GPS 좌표 얻기
 //---------------------
btnList.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
 // GPS 로그를 서버에 보내고 받아서 보는 모듈을 각자 구현해 주세요.
//Intent i = new Intent(mContext,GpsLog.class);
//startActivity(i);
}
 });
}
4. 지도 초기 설정 - 지도 불러 오기
//---------------------
// 지도 불러오기
//---------------------
private void initMap() {
mapView = (MapView) findViewById(R.id.mapview);
mc = (MapController)mapView.getController();

 // 아래 두개로 확대/축소 버튼 생성
 mapView.setBuiltInZoomControls(true);
 mapView.displayZoomControls(true);

 //지도 레벨 설정 max:21 / satellite :18
 mc.setZoom(20);
 //mc.setZoom(7); // 한국지도 레벨
 //mc.setZoom(13); // 광역시 정도 레벨
} 
5. GPS 작동 시키기, 좌표 받기 - 시작 버튼 클릭
public void runGPS()
 {
 btnUpdate.setEnabled(false);
this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
 initVar(); // 화면 갱신 하기 위한 값들
}
 });
 // 위치 매니저
 locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 if ( !locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
} else {
 //---------------------
 //1. GPS 시작
 //---------------------
 registerLocationListeners(); // 위치 수신자들 가동..
 //_send2Svr() ;
 // chkTimeOut(); // 특정 시간내에 응답없으면 강제 마무리 하게 하기 위해 /// 특히 실내에서..
 btnUpdate.setEnabled(true);
 }

}
5-1.
private void createLocationListeners()
 {
 // network를 통해 들어오는 좌표
listenerCoarse = new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle extras) {
switch ( status )
{
 case LocationProvider.OUT_OF_SERVICE:
 case LocationProvider.TEMPORARILY_UNAVAILABLE:
 locationAvailable = false;
 case LocationProvider.AVAILABLE:
 locationAvailable = true;
}
 }
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onLocationChanged(Location newLocation) {
currentLocation = newLocation;
if ( newLocation.getAccuracy()>1000 && newLocation.hasAccuracy())
{
//---------------------
//위치 매니저 제거 listenerCoarse
//---------------------
locManager.removeUpdates(this);
}
//---------------------
//1-1-1 위치 확인 : 현재위치 주소 가져오기
//---------------------
updateGps(currentLocation,0);
textView.setText("감지1COARSE [정확도:"+acc+"][provider:"+pro+"]");
}
};
listenerFine = new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle extras) {
switch ( status )
{
case LocationProvider.OUT_OF_SERVICE:
 case LocationProvider.TEMPORARILY_UNAVAILABLE:
 locationAvailable = false;
 case LocationProvider.AVAILABLE:
 locationAvailable = true;
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onLocationChanged(Location newLocation) {
 currentLocation = newLocation;
 if ( newLocation.getAccuracy()>1000 && newLocation.hasAccuracy())
 {
//---------------------
//위치 매니저 제거 listenerFine
//---------------------
locManager.removeUpdates(this);
 }
 //---------------------
 //1-1-1 위치 확인 : 현재위치 주소 가져오기
 //---------------------
 updateGps(currentLocation,0);
 textView.setText("감지2FINE [정확도: "+ acc+"][provider:"+pro+"]");
}
};
}
5-2.
private void chkTimeOut() {
Handler handler = new Handler();
handler.postDelayed( new Runnable() {
 @Override
 public void run() {
if ( lat == 0.0d ) {
 Criteria criteria = new Criteria();
 criteria.setAccuracy(Criteria.ACCURACY_FINE);
 String provider = locManager.getBestProvider(criteria, true);
Location location = locManager.getLastKnownLocation(provider);
 if ( location != null )
updateGps(location,1);
 String oldString4 = textView2.getText().toString();
 textView2.setText(oldString4+"LastKnown방식 [정확도:"+acc+"] [provider:" +pro+"]");
}
//---------------------
//위치 매니저 제거
//---------------------
removeListener();
 }
}, 15*1000 ); // 15 seconds
}

5-3.
public void removeListener()
{
 locManager.removeUpdates(listenerCoarse);
 locManager.removeUpdates(listenerFine);
}
private void updateGps(Location location, int type) {
// type = 0 : listener : 위치 수신자
// type = 1 : LastKnown : 최종 정보
if( fine == 1 ) return; // GPS에 갱신이 된 상태이면… 굳이 Network 변경정보를 안받게 다는 것임
if ( type == 0 ) { // type = 0 : listener : 위치 수신자
if ( location.getProvider().equals("gps")) {
gps_status="0";
fine=1;
}
else if (location.getProvider().equals("network")) {
gps_status="1";
}
} else { // type = 1 : LastKnown : 최종 정보 by chkTimeOut()
gps_status="2";
}
lat = location.getLatitude(); // Latitude
lng = location.getLongitude(); // Longitude
int accInt = (int)location.getAccuracy();
acc = Integer.toString(accInt); // 위치 정확도
pro = location.getProvider(); // 위치 제공자
updateAddress(location); // 주소 갱신
createAndShowCustomOverlay(location); // 지도 다시 그리기
}
5-4.
//---------------------
//---------------------
//1-1-1 : 현재 위치 지도 이동
//---------------------
protected void createAndShowCustomOverlay(Location newLocation) {
        List overlays = mapView.getOverlays();
        // first remove old overlay
        if (overlays.size() > 0) {
            for (Iterator iterator = overlays.iterator(); iterator.hasNext();) {
                iterator.next();
                iterator.remove();
            }
        }
        // transform the location to a geopoint
        GeoPoint geopoint = new GeoPoint((int)(newLocation.getLatitude() * 1E6),
            (int)(newLocation.getLongitude() * 1E6));
        // Create new Overlay
        MyOverlay overlay = new MyOverlay(geopoint);
        mapView.getOverlays().add(overlay);
        mapView.setSatellite(false); // 위성지도
        // move to location
        mapView.getController().animateTo(geopoint);
    }
    //---------------------
    //1-1-1 위치 확인 : 현재위치 주소 가져와서 변경
    //---------------------
private void updateAddress(Location location) {
    String add = "";
    // GeoCoder : 경도 위도 좌표로 주소 얻기
    Geocoder gc = new Geocoder(mapView.getContext(), Locale.getDefault());
    try {
        // 주소 가져오기
        List < Address > addresses = gc.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addresses.size() > 0) {
            for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex() + 1; i++) {
                add += addresses.get(0).getAddressLine(i);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringTokenizer st = new StringTokenizer(add);
    int i = 0;
    while (st.hasMoreTokens()) {
        addressArray[i++] = st.nextToken();
    }
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setTextColor(Color.BLUE);
    String oldString3 = textView.getText().toString();
    if (addressArray[0] == null) {
        textView.setText(oldString3 + ddressString);
    } else {
        // 주소 : 시 군 구
        textView.setText(oldString3 +
            addressArray[1] + " " + addressArray[2] + " " + addressArray[3] + " " + addressArray[4]);
    }
}
5-5.
public class MyOverlay extends Overlay {
    int INFO_WINDOW_WIDTH = 240; // 150; //125;
    int INFO_WINDOW_HEIGHT = 28; // 25;
    private GeoPoint geopoint = null;
    public MyOverlay(GeoPoint point) {
        geopoint = point;
    }
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        // Transfrom geoposition to Point on canvas
        Projection projection = mapView.getProjection();
        Point point = new Point();
        projection.toPixels(geopoint, point);
        //---add the marker---
        Bitmap userBmp = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.bubble);
        canvas.drawBitmap(userBmp, point.x, point.y, null);
        // 박스
        RectF infoWindowRect = new RectF(0, 0,
            INFO_WINDOW_WIDTH, // “여기”.length()*14, 문자열 길이로 하거나
            INFO_WINDOW_HEIGHT);
        // 지도 상대 좌표
        int infoWindowOffsetX = point.x; //-INFO_WINDOW_WIDTH/2;
        int infoWindowOffsetY = point.y; //-INFO_WINDOW_HEIGHT; // -bubbleIcon.getHeight();
        infoWindowRect.offset(infoWindowOffsetX, infoWindowOffsetY);
        // Draw inner info window
        canvas.drawRoundRect(infoWindowRect, 5, 5, getInnerPaint());
        // Draw border for info window
        canvas.drawRoundRect(infoWindowRect, 5, 5, getBorderPaint());
        // Draw the MapLocation's name
        //int TEXT_OFFSET_X = 10;
        //int TEXT_OFFSET_Y = 15;
        canvas.drawText(“여기”, // 표현할 글자
            infoWindowOffsetX + TEXT_OFFSET_X,
            infoWindowOffsetY + TEXT_OFFSET_Y,
            getTextPaint());
    }
    public Paint getInnerPaint() {
        if (innerPaint == null) {
            innerPaint = new Paint();
            innerPaint.setARGB(225, 75, 75, 75); //gray
            innerPaint.setAntiAlias(true);
        }
        return innerPaint;
    }
    public Paint getBorderPaint() {
        if (borderPaint == null) {
            borderPaint = new Paint();
            borderPaint.setARGB(255, 255, 255, 255);
            borderPaint.setAntiAlias(true);
            borderPaint.setStyle(Style.STROKE);
            borderPaint.setStrokeWidth(2);
        }
        return borderPaint;
    }
    public Paint getTextPaint() {
        if (textPaint == null) {
            textPaint = new Paint();
            textPaint.setARGB(255, 255, 255, 255);
            textPaint.setAntiAlias(true);
            textPaint.setTextSize(18);
            textPaint.setTypeface(Typeface.DEFAULT_BOLD);
        }
        return textPaint;
    }
}

'0.일반개발' 카테고리의 다른 글

Visual Studio 2010 프로젝트 속성 페이지  (0) 2015.12.03
$LogFile ( NTFS 볼륨 로그 )  (0) 2015.12.01
Eclipse Workingset  (0) 2015.11.18
IBM BlueMix  (0) 2015.11.17
호스트(Windows)에서 게스트(Linux)로 ssh 접속하기  (0) 2015.11.13


Workingset를 Eclipse에 추가 하기


1. eclipse설정를 통해서


http://sessionk.tistory.com/16


1) workspace

2) Open Perspective, Show View

3) Project Explorer부분에  Package Explorer를 추가 하기


2. WorkingSet 추가하는 과정


http://whiteship.tistory.com/1441


1) Package Explorer에서 Top Level Element를 Working Sets로 변경

2) Configure Working Sets로 추가 하기



'0.일반개발' 카테고리의 다른 글

$LogFile ( NTFS 볼륨 로그 )  (0) 2015.12.01
GPS 좌표 얻기  (0) 2015.11.25
IBM BlueMix  (0) 2015.11.17
호스트(Windows)에서 게스트(Linux)로 ssh 접속하기  (0) 2015.11.13
Bootstrap 시작하기  (0) 2015.11.11

+ Recent posts