'2015/10'에 해당되는 글 3

  1. 2015.10.25 백그라운드 프로세스 실행 시키기
  2. 2015.10.08 JAVA FTP 업데이트
  3. 2015.10.05 cocos2d-x 사용 방법
2015. 10. 25. 11:15 linux

node 실행 시켜 백그라운드로 설정하고 종료 시키는 방법 


방법1

jinukui-Mac-mini:Documents jinuk$ node app.js

Server Running at 

^Z//ctrl Z 로 일시 중지 

[1]+  Stopped                 node app.js

jinukui-Mac-mini:Documents jinuk$ bg//bg 명령어로 중지된 프로세스를 백그라운드로 실행

[1]+ node app.js &

jinukui-Mac-mini:Documents jinuk$ jobs//실행중인 프로세스를 확인

[1]+  Running                 node app.js &

jinukui-Mac-mini:Documents jinuk$ fg 1//실행중인 프로세스를 포그라운드로 올림 

node app.js

^C//ctrl c로 프로세스 종료 

jinukui-Mac-mini:Documents jinuk$ 






방법2

jinukui-Mac-mini:Documents jinuk$ node app.js &

[1] 4633

jinukui-Mac-mini:Documents jinuk$ Server Running at 


jinukui-Mac-mini:Documents jinuk$ ps aux | grep node

jinuk            4635   0.0  0.0  2432772    672 s000  S+   11:24AM   0:00.00 grep node

jinuk            4633   0.0  0.1  3037160  20576 s000  S    11:24AM   0:00.12 node app.js

jinukui-Mac-mini:Documents jinuk$ kill -9 4633




어쩌다 보면 나오는 에러인데 문제는 앱종료가 잘못 되어서 아직 까지 포트를 사용 하고 있다는 문제 

events.js:141

      throw er; // Unhandled 'error' event

      ^


Error: listen EADDRINUSE 127.0.0.1:1337

    at Object.exports._errnoException (util.js:874:11)

    at exports._exceptionWithHostPort (util.js:897:20)

    at Server._listen2 (net.js:1234:14)

    at listen (net.js:1270:10)

    at net.js:1379:9

    at doNTCallback3 (node.js:450:9)

    at process._tickCallback (node.js:356:17)

    at Function.Module.runMain (module.js:469:11)

    at startup (node.js:134:18)

    at node.js:961:3



해결 방법은 

jinukui-Mac-mini:Documents jinuk$ ps aux | grep node

jinuk            4570   0.0  0.1  3037160  20576   ??  S    11:10AM   0:00.12 node app.js

jinuk            4625   0.0  0.0  2432772    672 s000  S+   11:21AM   0:00.00 grep node

jinukui-Mac-mini:Documents jinuk$ kill -9 4570

jinukui-Mac-mini:Documents jinuk$ node app.js //다시 실행해보니 잘 돌아간다

Server Running at 

^C



posted by 욱이다
2015. 10. 8. 14:00 JAVA

서비스중인 파일을 실시간 값을 바꿔 올려야 할 필요가 있을 때 사용 

사용되는 라이브러리 

commons-net-3.3.jar

여기서 삽질은 ... FTP로 다운로드 받아서 파일로 저장해서 다시 읽어 들여서 파일 수정하고 파일 올렸더니 

인코딩 문제로 ...


그래서 다운받아 원하는 부분 수정하고 저장하는 방법으로 수정하니깐 된다 



import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.text.SimpleDateFormat;

import java.util.Arrays;

import java.util.regex.Matcher;

import java.util.regex.Pattern;


import org.apache.commons.net.ProtocolCommandEvent;

import org.apache.commons.net.ProtocolCommandListener;

import org.apache.commons.net.ftp.FTP;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPConnectionClosedException;

import org.apache.commons.net.ftp.FTPReply;


public class BatChFTPCategoryVersionnew {


final String SERVER_DOWNLOAD_FILE_TEMP = "info_";

final String SERVERINFO_REMOTE = "/was/resin3/webapps/ROOT/info.jsp";


String username = "admin";

String password = "password";


String local;

String remote;

String servers[] = {

"111.222.333.444","111.222.333.444","111.222.333.444" };

String dateChange;


/**

* @param args

*           

*/


public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println(Arrays.toString(args));


new BatChFTPCategoryVersionnew(args);

}


public BatChFTPCategoryVersionnew(String[] args) {


{

System.out.println("BATCH_SERVERINFO");


remote = SERVERINFO_REMOTE;

dateChange = (String) (new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()));

try {

if (callFtp(servers[1], false, "UTF-8"))

logicFtp();


} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


System.out.println("dfadsf");

}


public void logicFtp() {


for (int i = 0; i < servers.length; i++) {

if (!callFtp(servers[i], true, "UTF-8"))

break;


}


}


public boolean callFtp(String server, boolean writeFile, String encoding) {


boolean binaryTransfer = false, error = false;

FTPClient ftp;

ftp = new FTPClient();

ftp.setControlEncoding(encoding);

ftp.addProtocolCommandListener(new ProtocolCommandListener() {

@Override

public void protocolReplyReceived(ProtocolCommandEvent arg0) {


printLog("receive : " + arg0.getMessage());

}


@Override

public void protocolCommandSent(ProtocolCommandEvent arg0) {


if (!arg0.getCommand().equals("PASS"))

printLog("send : " + arg0.getCommand() + " => " + arg0.getMessage());

}

});


try {

int reply;

ftp.connect(server);

printLog("Connected to " + server + ".");


// After connection attempt, you should check the reply code to

// verify

// success.

reply = ftp.getReplyCode();


if (!FTPReply.isPositiveCompletion(reply)) {

ftp.disconnect();

printLog("FTP server refused connection.");

return false;// System.exit(1);

}

} catch (IOException e) {

if (ftp.isConnected()) {

try {

ftp.disconnect();


} catch (IOException f) {

// do nothing

}

}

printLog("Could not connect to server.");

e.printStackTrace();

return false;// System.exit(1);

}


__main: try {

if (!ftp.login(username, password)) {

printLog("LOGIN FAIL");

ftp.logout();

ftp.disconnect();

error = true;

break __main;

}

printLog("LOGIN SUCCESS");


ftp.setFileType(FTP.ASCII_FILE_TYPE);


ftp.enterLocalPassiveMode();


String tempPath = System.getProperty("user.dir").replace("\\src", "") + "\\" + SERVER_DOWNLOAD_FILE_TEMP

+ dateChange + ".jsp";

System.out.println(tempPath);

if (writeFile) {


FileInputStream input = new FileInputStream(new File(tempPath));


boolean fcheck = ftp.storeFile(remote, input);

input.close();

System.out.println("remote >>>>>>>>>>>>>>>>>>>>>>>>>\n " + remote);

System.out.println("fcheck >>>>>>>>>>>>>>>>>>>>>>>>>\n " + fcheck);


} else {


String remoteFile = SERVERINFO_REMOTE;


File f = new File(tempPath);

if (f.exists())

f.delete();


InputStream inputStream = ftp.retrieveFileStream(remoteFile);

byte[] bytesArray = new byte[inputStream.available()];

inputStream.read(bytesArray);


{


String str = new String(bytesArray, "UTF-8");

Pattern p = Pattern.compile("\"categoryVersion\".*:.*\"[0-9]{14}\"");

Matcher m = p.matcher(str);

if (m.find()) {

String s = m.group(0);

str = str.replace(s, "\"categoryVersion\"" + ":\"" + dateChange + "\"");

System.out.println("**************************\n" + str);

}

OutputStream outputStream2 = new BufferedOutputStream(new FileOutputStream(f));

outputStream2.write(str.getBytes("UTF-8"));

outputStream2.close();

inputStream.close();

if (str.length() == 0)

error = true;


File fcheck = new File(tempPath);

System.out.println("exists " + fcheck.exists() + " length " + fcheck.length());

if (!fcheck.exists() || fcheck.length() == 0)

error = true;

}


}


ftp.logout();

} catch (Exception e) {

error = true;

printLog("Server closed connection error." + e.toString());


e.printStackTrace();

} finally {

if (ftp.isConnected()) {

try {

ftp.disconnect();

} catch (IOException f) {

// do nothing

}

}

}

if (error)

printLog("Server end connection ERROR ");


printLog("===========================================================");

return !error;

// System.exit(error ? 1 : 0);

} //


public void printLog(String str) {

System.out.println(str);

}

}



컴파일 배치 

d:

cd D:\PROJECT\tempworkspace\BatChFTPCategoryVersionnew 


javac -cp libs\commons-net-3.3.jar src\BatChFTPCategoryVersionnew .java

cd src

java -classpath "D:\PROJECT\tempworkspace\BatChFTPCategoryVersionnew \libs\commons-net-3.3.jar;" BatChFTPCategoryVersionnew


'JAVA' 카테고리의 다른 글

jsp  (0) 2015.04.04
이클립스 워크 스페이스 삭제후 에러 발생  (0) 2014.12.03
서버 확인후 메시지 보내기  (0) 2014.10.20
java 이미지 바이트 조합  (0) 2014.01.09
자바 정렬  (0) 2011.12.01
posted by 욱이다
2015. 10. 5. 19:09 게임

http://www.cocos2d-x.org/download


새로운 프로젝트 만드는 방법 

./cocos new testcocos2d -p com.sons.testcocos2d -l cpp -d /Users/jinuk/Project/cocos 

==설명===

testcocos2d 프로젝트명

com.sons.testcocos2d 패키지명

cpp 타입

/Users/jinuk/Project/cocos 프로젝트 생성위치 

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



안드로이드 컴파일위한 다운로드 

ant 다운로드 http://ant.apache.org/bindownload.cgi

ndk 다운로드 https://developer.android.com/ndk/downloads/index.html

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



ndk 설치 방법 

sudo chmod a+x android-ndk-r10d-darwin-x86_64.bin

./android-ndk-r10d-darwin-x86_64.bin

이렇게 하면 폴더에 압축이 풀린다 

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



세팅방법 

cocos루트 폴더에서 

setup.py 실행

실행 하고 상황에 맞는 경로를 넣을때 

/Users/jinuk/sdk/android-ndk-r10e/

/Users/jinuk/sdk/apache-ant-1.9.6/bin/

이렇게 상황에 맞게 넣어야된다 끝에 / 이게 중요하다 

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



 cocos path 설정

vi /Users/jinuk/.bash_profile

export PATH=/Users/jinuk/sdk/cocos2d-x-3.8.1/tools/cocos2d-console/bin/cocos:$PATH

적용 ~

source /Users/jinuk/.bash_profile

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




소스파일이나 라이브러리 파일등을 추가할때 수정해야될 부분 자세한 사항은 검색해서 ~

/Users/jinuk/Project/cocos/testcocos2d/proj.android/jni/Android.mk

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




안드로이드 실행은 

cocos run testcocos2d -p android

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




이클립스에서 땡겨 쓰기 

/Users/jinuk/Project/cocos/testcocos2d/proj.android 

경로를 임포트한다 

/Users/jinuk/Project/cocos/testcocos2d/cocos2d/cocos/platform/android/java

경로를 임포트한다 

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

'게임' 카테고리의 다른 글

발로만든 슬라이드웹  (0) 2012.06.22
각시탈 만화 살자톡으로 보자  (0) 2012.06.21
짜요짜요타이쿤5  (0) 2011.03.29
짜요짜요타이쿤4  (0) 2011.03.29
메이저 오일 컴퍼니 동영상  (0) 2010.02.12
posted by 욱이다
prev 1 next