다음과 같이 Stream을 사용하였다면, 한글 문자열은 100% 깨집니다.
…… 생략 ……
reader = new StreamReader(ns);
writer = new StreamWriter(ns);
…… 생략 ……

다음과 Encoding을 설정하여 주면, 한글 문자열이 깨지지 않고 처리됩니다.
…… 생략 ……
reader = new StreamReader(ns, System.Text.Encoding.Default);
writer = new StreamWriter(ns, System.Text.Encoding.Default);
…… 생략 ……

변경하고자 하는 다른 Encode가 있다면 그것으로 설정하여도 됩니다.

Dim strBuffer as String
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) 
    Dim temp As String
    Dim intDelimiter As Integer
    intDelimiter = 0 
    Winsock1.GetData temp, vbString, bytesTotal 
    strBuffer = strBuffer & temp 
    Do 
        DoEvents ' DoEvents는 상황에 따라서 사용합니다.
        intDelimiter = InStr(1, strBuffer, vbCrLf) 
        If intDelimiter > 0 Then 
            temp = Mid(strBuffer, 1, intDelimiter - 1) 
            strBuffer = Mid(strBuffer, intDelimiter + 1, Len(strBuffer)) 
            ' CRLF로 나누어진 temp를 처리할 루틴 입력
        End If 
    Loop Until intDelimiter = 0 
End Sub

[참고] http://support.microsoft.com/kb/602093/ko


1. gmail.com에 로그인 한 다음 우측 상단의 Settings->Forwarding and POP 메뉴로 들어간다. 그러면 아래와 같은 메뉴가 나타나는데, Enable POP for all mail (even mail that's already been downloaded)를 체크한 다음 Save Changes버튼을 누른다.


2. 아웃룩을 실행시킨 후, 도구->계정->추가->메일을 선택하여 아래와 같은 화면이 나타나도록 한 후, 사용자 이름을 입력한 후 다음을 누른다.

3. 사용자의 메일 주소를 입력한 후 다음 버튼을 누른다.

4. 아래 화면 처럼 받은 메일 서버 유형은 POP3, 받은 메일 서버는 pop.gmail.com, 그리고 보내는 메일 서버는 smtp.gmail.com으로 입력한 후 다음 메뉴로 넘어간 후, 설정을 완료 시킨다.

5. 다시, 도구->계정->메일(탭)을 선택한 후, 해당 메일을 더블클릭을 하여, 서버탭 버튼을 선택한 후, 보내는 서버에서 인증 필요를 체크한다.

6. 고급 탭을 눌려서, 아래 화면이 나오도록 한다. 보내는 메일은 465(또는 587)으로 하고, 보안 연결 필요를 체크하고, 받는 메일은 995로 하고, 역시 보안 연결 필요를 체크한다. 그리고, '서버에 편지 복사본 저장'과 '지운 편지함에서 삭제하면 서버에서 제거'도 필요하면 체크한다.

7. 아웃룩에서 배달 버튼을 눌려서, gmail로 부터 메일을 전달받는다.

sendmail.cf 파일을 열어서 아래와 같이 설정한다.

1. 보내는 메세지의 크기 지정은 아래와 같은 문장을 찾아서, 주석('#')을 제거하고, MaxMessageSize의 값을 적절하게 수정하면 된다. 값의 단위는 byte이다.

......중간 생략......
# maximum message size
#O MaxMessageSize=1000000
......중간 생략......

2. 한번에 보낼 메일의 갯수는 아래와 같은 문장을 찾아서, 주석('#')을 제거하고, MaxRecipientsPerMessage의 값을 적절하게 수정하면 된다.

......중간 생략......
# maximum number of recipients per SMTP envelope
#O MaxRecipientsPerMessage=100
......중간 생략......

1. 시스템 환경

▲구현하고자 하는 Master/Slave Replication과 시스템 환경

2. Replication 설정
Master Server (Linux)
① Replication을 위한 계정을 추가한다. 다만 4.0.2 이전 버젼의 MySQL 사용자일 경우는 REPLICATION SLAVE의 권한설정 부분이 없으므로, 대신에 FILE 권한설정 사용하여야 한다. (user id와 user password는 설정하고자 하는 것으로 하면 된다. 여기서는 둘다 repli로 설정)
mysql> GRANT REPLICATION SLAVE ON *.*
   -> TO ‘user id’@’%’ IDENTIFIED BY ‘user password’;

*4.0.2 이전 버젼은 다음과 같이 한다.
mysql> GRANT FILE ON *.*
   -> TO ‘user id’@’%’ IDENTIFIED BY ‘user password’;

② Replication을 적용할 테이블을 생성한다.(여기서는 Test DB에 repli_test 테이블을 생성하기로 한다.)
mysql> use test;
mysql> create table repli_test (name varchar(255));

③ MySQL 서비스를 중지 시킨다.

④ /etc/my.cnf 파일을 생성하고, 아래의 내용 중 노란색으로 마킹된 내용을 추가하거나 수정한다. (my.cnf 파일은 설치시 생성되는 파일이 아니므로, 파일을 직접 작성하거나, Source를 이용해서 설치했을 경우, [mysql 설치 디렉토리]/share/mysql 디렉토리에 my-xxx.cnf 파일들이 있으므로 적당히 골라서 수정을 하여 사용한다.) server-id는 서버끼리 중복되지 않는 값을 지정하여 줄 수가 있으며, 지정범위는 1부터 2^32-1(=4294967295)까지 이다.
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /home/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password     = your_password
port        = 3306
socket       = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port        = 3306
socket       = /tmp/mysql.sock
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
net_buffer_length = 2K
thread_stack = 64K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id     = 1

# Uncomment the following if you want to log updates
log-bin

# Uncomment the following if you are NOT using BDB tables
#skip-bdb

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /home/mysql/data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /home/mysql/data/
#innodb_log_arch_dir = /home/mysql/data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

⑤ [mysql 설치 디렉토리]/data/test 디렉토리로 이동하여 Replication을 적용할 Table을 백업해놓는다.(백업한 Table 파일은 Slave DB Server에 복사해서 사용할 것이다. 사실 이렇게 파일 복사 말고 Table export를 하여 Slave DB에 import 시켜도 된다.)
# ls
repli_test.MYD repli_test.MYI repli_test.frm
# tar cvzf repli_test.tar.gz *

Slave Server (Windows 2000 Pro)
⑥ MySQL 서비스를 중지 시킨다.

⑦ C:\WINNT\my.ini 파일을 아래와 같이 노란색으로 마킹된 내용을 추가하거나 수정한다.
[WinMySQLAdmin]
Server=C:/mysql/bin/mysqld-nt.exe
[mysqld]
master_host=192.168.0.1
master-user=repli
master-password=repli
master-port=3306
server-id=2

⑧ Master Server에서 백업한 Replication을 적용할 Table 파일을 C:\mysql\data\test 디렉토리에 압축을 풀어놓거나 복사해 놓는다. (⑤과정참조)


Master & Slave Server
⑨ Master Server의 MySQL 서비스를 시작한 후, Slave Server의 MySQL 서비스를 시작한다.

3. Test 및 Monitoring 하기
Test는 간단하게 Master Server에서 Data값을 Insert, Update, Delete를 해보고, 결과가 Slave Server에도 반영이 되는지 살펴보면 된다.(Master/Slave Replication 구성으로는 Slaver Server에서 Data값을 Insert, Update, Delete를 해도 Master Server에는 반영이 되지 않는다.)
*Master Server
mysql> insert into repli_test value ('test1');
Query OK, 1 row affected (0.00 sec)

*Slave Server
mysql> select * from repli_test;
+-------+
| name  |
+-------+
| test1 |
+-------+
4 rows in set (0.01 sec)

Master와 Slave Server의 상태를 확인하고 싶을 때에는 다음과 같은 명령어를 실행한다.
*Master Server
mysql> show master status \G
*************************** 1. row ***************************
       File: XXX-bin.002
    Position: 300
  Binlog_do_db:
Binlog_ignore_db:
1 row in set (0.00 sec)

*Slave Server
mysql> show slave status \G
*************************** 1. row ***************************
      Master_Host: XXX.XXX.XXX
      Master_User: repli
      Master_Port: 3306
    Connect_retry: 60
   Master_Log_File: XXX-bin.002
Read_Master_Log_Pos: 300
    Relay_Log_File: XXX-relay-bin.002
    Relay_Log_Pos: 456
Relay_Master_Log_File: XXX-bin.002
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
   Replicate_do_db:
Replicate_ignore_db:
      Last_errno: 0
      Last_error:
     Skip_counter: 0
Exec_master_log_pos: 300
   Relay_log_space: 452
1 row in set (0.00 sec)

Slave Server에서 Replication을 중단(slave stop)하거나, 다시 시작(slave start)할 때에는 다음과 같은 명령어 실행한다.
*Slave Server
mysql> slave stop;
Query OK, 0 rows affected (20.69 sec)

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

4. Replication을 응용한 구성의 예

▲Dual-Master Replication

▲Replication Ring

▲Relay

▲Load-Balancing Reads

5. 참고자료

1. 설치 환경
-H/W : CPU-Cel 500/RAM-96M/HDD-8G
-O/S : Slackware Linux 8.1

2. 준비물
-apache_1.3.31.tar.gz (http://httpd.apache.org/download.cgi )
-jakatra-tomcat-4.1.31.tar.gz (http://mirror.apache.or.kr/jakarta/tomcat-4/v4.1.31/bin )
-jakarta-tomcat-connectors-4.1.31-src.tar.gz (http://mirror.apache.or.kr/jakarta/tomcat-4/v4.1.31/src )
-j2sdk-1_4_2_06-linux-i586.bin (http://java.sun.com/j2se/1.4.2/download.html )

3. 설치
① apache를 설치한다.
# tar xvzf apache_1.3.31.tar.gz
# cd apache_1.3.31
# ./configure --prefix=/usr/local/apache \
--htdocsdir=/home/apache/htdocs \
--iconsdir=/home/apache/icons \
--cgidir=/home/apache/cgi-bin \
--logfiledir=/var/log/apache \
--enable-shared=max \
--enable-module=so \
--enable-rule=SHARED_CORE
......중간 생략......
# make; make install

② j2sdk를 설치한다.
# chmod 777 j2sdk-1_4_2_06-linux-i586.bin
# ./j2sdk-1_4_2_06-linux-i586.bin
......중간 생략......
# mv j2sdk1.4.2_06 /usr/local/java

③ tomcat을 설치한다.
# tar xvzf jakatra-tomcat-4.1.31.tar.gz
# mv jakatra-tomcat-4.1.31 /usr/local/tomcat

④ tomcat-connector를 설치한다.(설치 후 /usr/local/apache/libexec 디렉토리에 mod_jk.so 파일이 생성되었는지 확인한다.)
# tar xvzf jakarta-tomcat-connectors-4.1.31-src.tar.gz
# cd jakarta-tomcat-connectors-4.1.31-src
# ./configure --with-apxs=/usr/local/apache/bin/apxs
......중간 생략......
# make; make install

⑤ /usr/local/apache/conf/httpd.conf 파일에 tomcat에 대한 설정 내용을 추가한다.
......중간 생략......
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Please read the file http://httpd.apache.org/docs/dso.html for more
# details about the DSO mechanism and run `httpd -l' for the list of already
# built-in (statically linked and thus always available) modules in your httpd
# binary.
#
# Note: The order in which modules are loaded is important. Don't change
# the order below without expert advice.
#
# Example:
# LoadModule foo_module libexec/mod_foo.so
LoadModule env_module      libexec/mod_env.so
LoadModule config_log_module libexec/mod_log_config.so
LoadModule mime_module     libexec/mod_mime.so
LoadModule negotiation_module libexec/mod_negotiation.so
LoadModule status_module    libexec/mod_status.so
LoadModule includes_module   libexec/mod_include.so
LoadModule autoindex_module  libexec/mod_autoindex.so
LoadModule dir_module      libexec/mod_dir.so
LoadModule cgi_module      libexec/mod_cgi.so
LoadModule asis_module     libexec/mod_asis.so
LoadModule imap_module     libexec/mod_imap.so
LoadModule action_module    libexec/mod_actions.so
LoadModule userdir_module   libexec/mod_userdir.so
LoadModule alias_module     libexec/mod_alias.so
LoadModule access_module    libexec/mod_access.so
LoadModule auth_module     libexec/mod_auth.so
LoadModule setenvif_module   libexec/mod_setenvif.so
LoadModule php4_module     libexec/libphp4.so
LoadModule jk_module       libexec/mod_jk.so

# Reconstruction of the complete module list from all available modules
# (static and shared ones) to achieve correct module execution order.
# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]
ClearModuleList
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_status.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
AddModule mod_userdir.c
AddModule mod_alias.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_so.c
AddModule mod_setenvif.c
AddModule mod_php4.c
AddModule mod_jk.c
......중간 생략......
#
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
  DirectoryIndex index.html index.php index.jsp
</IfModule>

#
# AccessFileName: The name of the file to look for in each directory
# for access control information.
#
AccessFileName .htaccess
......중간 생략......(마지막 부분)
# Configure mod_jk
JkMount /*.jsp ajp13
JkMount /webapps/* ajp13
JkMount /ROOT/* ajp13
JkWorkersFile /usr/local/tomcat/conf/workers.properties
JkLogFile /var/logs/apache/mod_jk.log
JkLogLevel info

⑥ /etc/profile 파일에 java와 tomcat에 대한 설정 내용을 추가한다.
......중간 생략......
# For Java
PATH="$PATH:/usr/local/java/bin"
export JAVA_HOME="/usr/local/java"
export CLASSPATH=./:$JAVA_HOME/lib/tools.jar:/usr/local/tomcat/common/lib/servlet.jar
export PATH=$PATH:$JAVA_HOME/bin

# For Tomcat
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export CATALINA_HOME
......중간 생략......

⑦ 설정이 바뀐 /etc/profile을 시스템에 적용한다.
# source /etc/profile

⑧ /usr/local/tomcat/conf/workers.properties 파일에 java와 tomcat에 대한 설정 내용을 추가한다.(workers.properties 파일이 없으면 생성)
......중간 생략......
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/java
worker.list=ajp12, ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
......중간 생략......

⑩ /usr/local/tomcat/conf/server.xml 파일에 apache에서 설정한 서버의 호스트 도메인명과 document root 디렉토리를 설정하여 준다.(이 설정을 하지 않으면, jsp의 실행은 /usr/local/tomcat/webapps/ROOT 디렉토리에서만 된다.)
......중간 생략......(마지막 부분)
         <Environment name="maxExemptions" type="java.lang.Integer" value="15"/>
         <Parameter name="context.param.name" value="context.param.value" override="false"/>
         <Resource name="jdbc/EmployeeAppDb" auth="SERVLET" type="javax.sql.DataSource"/>
         <ResourceParams name="jdbc/EmployeeAppDb">
           <parameter><name>username</name><value>sa</value></parameter>
           <parameter><name>password</name><value></value></parameter>
           <parameter><name>driverClassName</name>
             <value>org.hsql.jdbcDriver</value></parameter>
           <parameter><name>url</name>
             <value>jdbc:HypersonicSQL:database</value></parameter>
         </ResourceParams>
         <Resource name="mail/Session" auth="Container" type="javax.mail.Session"/>
         <ResourceParams name="mail/Session">
           <parameter>
             <name>mail.smtp.host</name>
             <value>localhost</value>
           </parameter>
         </ResourceParams>
         <ResourceLink name="linkToGlobalResource" global="simpleValue" type="java.lang.Integer"/>
       </Context>
     </Host>
    <Host name="서버의 호스트 도메인명">
      <Context path="" docBase="/home/apache/htdocs" reloadable="true"/>
       <Alias>서버의 호스트 도메인명</Alias>
     </Host>
   </Engine>
</Service>
</Server>

⑪ apache와 tomcat을 실행한다.
# /usr/local/apache/bin/apachectl start
# /usr/local/tomcat/bin/catalina.sh start (혹은 startup.sh)

⑫ test.jsp 코드를 입력하여 올바르게 출력되는지 확인한다.
<%@ page language="java" %>
<% out.println("hello! JSP"); %>

+ Recent posts