CRUD는 무엇인가?

 

CRUD란 용어는 Create, Read, Update, Delete 또는 Create, Retrieve, Update, Destroy를 묶어서 이야기 하는 용어로 대부분의 software가 가지는 기본적인 데이터 처리기능을 지칭한다.

Create(생성), Read/Retrieve(읽기/인출), update(갱신), Delete/Destroy(삭제/파괴)의 기능을 하지 못하는 소프트웨어는 완전하다고 할 수 없다는 말이 있을 정도로 기본적인 기능에 속하기 때문에 한묶음으로 이야기 되어진다. 이러한 기능을 하는 대표적인 프로그램들로는 주소록앱이나 달력앱 그리고 Mysql같은 DB관리 software등이 있다.

Posted by duehd88
,

IHTMLDocument2, IHTMLElementCollection, IHTMLElement 등등을 쓰기 위해선 mshtml을 using해주어야 한다.

얘는 참조우클릭후참조추가 - COM - Microsoft HTML Object Library 체크 후 확인하면된다.

'Programing > C#' 카테고리의 다른 글

[C#] SHDocVw로 InternetExplorer 객체 사용하기  (0) 2015.06.22
Posted by duehd88
,

SHDocVw를 이용해 InternetExplorer객체를 이용해보는 프로젝트를 하려고 하는데 당최 찾을 수가 없었다 알고보니 미리 참조가 되어있지 않았던 탓

C:\Windows\System32\shdocvw.dll를 참조하기위해 프로젝트의 참조 부분에 Microsoft Internet control을 추가 해주면 된다.

참조에서 마우스 우클릭후 참조추가 >COM>Microsoft Internet Controls 체크 후 확인

 

자 이제 사용하면된다.

 

간단한 예제

 

    SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
    ie.Visible = true;
    ie.Navigate("http://naver.com/");

 

이렇게 하면 네이버에 접속된 익스플로러 새창이 뜬다.

 

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

참고로 메서드위에 DllImport를 이용하면 참조하지 않고 사용이 된다고 한다.

대신 static extern으로 이용가능

 

using System.Runtime.InteropServices;

[DllImport("C:\\Windows\\System32\\shdocvw.dll")]

 private(public) static extern 데이터타입 함수명(파라미터);

'Programing > C#' 카테고리의 다른 글

[C#] mshtml 사용하기  (0) 2015.06.22
Posted by duehd88
,

#define bzero(b,len) (memset(b,0,len))

#define bcopy(b1,b2,len) (memcpy(b1,b2,len))

 

//#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)

//#define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)

 

...그냥 memset쓰자...

memset과 bzero의 비교 : http://fdiv.net/2009/01/14/memset-vs-bzero-ultimate-showdown

'Programing > C' 카테고리의 다른 글

Windows, Unix and ANSI C API Comparison  (0) 2015.05.22
unix의 drand48()와 srand48() windows에서 사용하기  (0) 2015.05.22
Posted by duehd88
,

아래내용 원본 링크 - http://blogs.msdn.com/b/csliu/archive/2009/03/20/windows-unix-and-ansi-c-api-comparison.aspx

Unix to Windows Porting Dictionary for HPC 링크 - http://66.165.136.43/dictionary/index.php

 

1. I/O
1. 1 File & Directory

Subject Windows UNIX C Library Comments
Console I/O AllocConsole terminal I/O N/A
Console I/O FreeConsole terminal I/O N/A
Console I/O ReadConsole read getc, scanf, gets
Console I/O SetConsoleMode ioctl N/A
Console I/O WriteConsole write putc, printf, puts
Directory Mgt CreateDirectory mkdir* N/A Make a new directory
Directory Mgt FindClose closedir* N/A Close a directory search handle
Directory Mgt FindFirstFile opendir*, readdir* N/A Find first file matching a pattern
Directory Mgt FindNextFile readdir* N/A Find subsequent files
Directory Mgt GetCurrentDirectory getcwd* N/A
Directory Mgt GetFullPathName N/A N/A
Directory Mgt GetSystemDirectory Well-known pathnames N/A
Directory Mgt RemoveDirectory rmdir, unlink* remove
Directory Mgt SearchPath Use opendir, readdir N/A Search for a file on a specified path
Directory Mgt SetCurrentDirectory chdir*, fchdir N/A Change the working directory
Error Handling FormatMessage strerror perror
Error Handling GetLastError errno errno Global variable
Error Handling SetLastError errno errno Global variable
File Locking LockFile fcntl (cmd=F_GETLK, ..) N/A
File Locking LockFileEx fcntl (cmd=F_GETLK, ..) N/A
File Locking UnlockFile fcntl (cmd=F_GETLK, ..) N/A
File Locking UnlockFileEx fcntl (cmd=F_GETLK, ..) N/A
File System CloseHandle (file handle) close* fclose CloseHandle is not limited to files
File System CopyFile open; read; write; close fopen; fread; fwrite; fclose Duplicate a file
File System CreateFile open*, creat* fopen Open/create a file
File System DeleteFile unlink* remove Delete a file
File System FlushFileBuffers fsynch fflush Write file buffers
File System GetFileAttributes stat*, fstat*, lstat N/A
File System GetFileInformationByHandle stat*, fstat*, lstat N/A Fill structure with file info
File System GetFileSize stat*, fstat*, lstat ftell, fseek Get length of file in bytes
File System GetFileTime stat*, fstat*, lstat N/A
File System GetFileType stat*, fstat*, lstat N/A Check for character stream device or file
File System GetStdHandle Use file desc 0, 1, or 2 Use stdin, stdout, stderr
File System GetTempFileName Use C library tmpnam Create a unique file name
File System GetTempFileName, CreateFile Use C library tmpfile Create a temporary file
File System GetTempPath /temp path N/A Directory for temp files
File System MoveFile, MoveFileEx Use C library rename Rename a file or directory
File System CreateHardLink link, unlink* N/A Windows does not support links
File System N/A symlink N/A Create a symbolic link
File System N/A readlink N/A Read name in a symbolic link
File System N/A, ReadFile returns 0 bytes N/A, read returns 0 bytes feof Rest for end of file
File System N/A, use multiple ReadFiles readv N/A, use multiple freads Scatter read
File System N/A, use multiple WriteFiles writev N/A, use multiple fwrites Gather write
File System ReadFile read fread Read data from a file
File System SetEndOfFile chsize* N/A
File System SetFileAttributes fcntl N/A
File System SetFilePointer lseek fseek Set file pointer
FileSystem SetFilePointer (to 0) lseek (0) rewind
File System SetFileTime utime* N/A
File System SetStdHandle close, dup*, dup2*, or fcntl freopen dup2 or fcntl
File System WriteFile write fwrite Write data to a file

1.2 Async I/O
Subject Windows UNIX C Library Comments
Asynch I/O GetOverlappedResult N/A N/A
Asynch I/O ReadFileEx N/A N/A Extended I/O with completion routine
Asynch I/O SleepEx N/A N/A Alertable wait
Asynch I/O WaitForMultipleObjects (file handles) poll, select N/A
Asynch I/O WaitForMultipleObjectsEx N/A N/A Alertable wait
Asynch I/O WriteFileEx N/A N/A Extended I/O with completion routine
Asynch I/O WaitForSingleObjectEx waitpid N/A Alertable wait

2. Memory & DLL
Subject Windows UNIX C Library
Mapped Files CreateFileMapping shmget N/A
Mapped Files MapViewOfFile mmap, shmat N/A
Mapped Files MapViewOfFileEx mmap, shmat N/A
Mapped Files OpenFileMapping shmget N/A
Mapped Files UnmapViewOfFile munmap, shmdt, shmctl N/A
Memory Mgt GetProcessHeap N/A N/A
Memory Mgt GetSystemInfo N/A N/A
Memory Mgt HeapAlloc sbrk, brk, or C library malloc, calloc
Memory Mgt HeapCreate N/A N/A
Memory Mgt HeapDestroy N/A N/A
Memory Mgt HeapFree Use C library free
Memory Mgt HeapReAlloc Use C library realloc
Memory Mgt HeapSize N/A N/A
Shared Memory CloseHandle (map handle) shmctl N/A
Shared Memory CreateFileMapping, OpenFileMapping shmget N/A
Shared Memory MapViewOfFile shmat N/A
Shared Memory UnmapViewOfFile shmdt N/A
DLLs LoadLibrary dlopen N/A
DLLs FreeLibrary dlclose N/A
DLLs GetProcAddress dlsyn N/A
DLLs DllMain pthread_once N/A

3. Process & Thread
3.1 Process

Subject Windows UNIX C Library Comments
Process Mgt CreateProcess fork (); execl ()*, system() N/A There are 6 execxx functions
Process Mgt ExitProcess _exit exit
Process Mgt GetCommandLine argv [] argv []
Process Mgt GetCurrentProcess getpid* N/A
Process Mgt GetCurrentProcessId getpid* N/A
Process Mgt GetEnvironmentStrings N/A getenv
Process Mgt GetEnvironmentVariable N/A getenv
Process Mgt GetExitCodeProcess wait, waitpid N/A
Process Mgt GetProcessTimes times, wait3, wait4 N/A
Process Mgt GetProcessWorkingSetSize wait3, wait4 N/A
Process Mgt N/A execl*, execv*, execle*, execve*, execlp*, execvp* N/A Windows does not have a direct equivalent
Process Mgt N/A fork, vfork N/A Windows does not have a direct equivalent
Process Mgt N/A getppid N/A No parent/child relationships in Windows
Process Mgt N/A getgid, getegid N/A No process groups in Windows
Process Mgt N/A getpgrp N/A
Process Mgt N/A setpgid N/A
Process Mgt N/A setsid N/A
Process Mgt N/A tcgetpgrp N/A
Process Mgt N/A tcsetpgrp N/A
Process Mgt OpenProcess N/A N/A
Process Mgt SetEnvironmentVariable putenv N/A putenv is not part of the Standard C library
Process Mgt TerminateProcess kill N/A
Synch: Process WaitForMultipleObjects (process handles) waitpid N/A
Synch: Process WaitForSingleObject (process handle) wait, waitpid N/A
Timers KillTimer alarm (0) N/A
Timers SetTimer alarm N/A
Timers Sleep sleep N/A
Timers Sleep poll or select, no file descriptor N/A

3.2 Thread
Subject Windows UNIX/Pthreads Comments
Thread Mgt CreateRemoteThread N/A
TLS TlsAlloc pthread_key_alloc
TLS TlsFree pthread_key_delete
TLS TlsGetValue pthread_getspecific
TLS TlsSetValue pthread_setspecific
Thread Mgt CreateThread, _beginthreadex pthread_create
Thread Mgt ExitThread, _endthreadex pthread_exit
Thread Mgt GetCurrentThread pthread_self
Thread Mgt GetCurrentThreadId N/A
Thread Mgt GetExitCodeThread pthread_yield
Thread Mgt ResumeThread N/A
Thread Mgt SuspendThread N/A
Thread Mgt TerminateThread pthread_cancel pthread_cancel is safer
Thread Mgt WaitForSingleObject(thread handle) pthread_join
Thread Priority GetPriorityClass pthread_attr_getschedpolicy, getpriority
Thread Priority GetThreadPriority pthread_attr_getschedparam
Thread Priority SetPriorityClass pthread_attr_setschedpolicy, setpriority, nice
Thread Priority SetThreadPriority pthread_attr_setschedparam
Note: Pthreads, while a part of all modern UNIX offerings, are available on non-UNIX systems as well.

3.3 Synchronization
Subject Windows UNIX/Pthreads Comments
Synch: CritSec DeleteCriticalSection Use mutexes to emulate critical sections. Some systems provide proprietary equivalents. C library is not applicable
Synch: CritSec EnterCriticalSection C library is not applicable
Synch: CritSec InitializeCriticalSection
Synch: CritSec LeaveCriticalSection
Synch: Event CloseHandle (event handle) pthread_cond_destroy
Synch: Event CreateEvent pthread_cond_init
Synch: Event PulseEvent pthread_cond_signal Manual-reset event
Synch: Event ResetEvent N/A
Synch: Event SetEvent pthread_cond_broadcast Auto-reset event
Synch: Event WaitForSingleObject (event handle) pthread_cond_wait
Synch: Event WaitForSingleObject (event handle) pthread_timed_wait
Synch: Mutex CloseHandle (mutex handle) pthread_mutex_destroy
Synch: Mutex CreateMutex pthread_mutex_init
Synch: Mutex ReleaseMutex pthread_mutex_unlock
Synch: Mutex WaitForSingleObject (mutex handle) pthread_mutex_lock
Synch: Sem CreateSemaphore semget
Synch: Sem N/A semctl Windows does not directly support all these options
Synch: Sem OpenSemaphore semget
Synch: Sem ReleaseSemaphore semop (+)
Synch: Sem WaitForSingleObject (semaphore handle) semop (-) Windows can wait for only one count

3.4 IPC
Subject Windows UNIX C Library Comments
IPC CallNamedPipe N/A N/A CreateFile, WriteFile, ReadFile, CloseHandle
IPC CloseHandle (pipe handle) close, msgctl pclose Not part of the Standard C library—see Stevens
IPC ConnectNamedPipe N/A N/A
IPC CreateMailslot N/A N/A
IPC CreateNamedPipe mkfifo, msgget N/A
IPC CreatePipe pipe popen Not part of the Standard C library—see Stevens
IPC DuplicateHandle dup, dup2, or fcntl N/A Or use file names CONIN$, CONOUT$
IPC GetNamedPipeHandleState stat, fstat, lstat64 N/A
IPC GetNamedPipeInfo stat, fstat, lstat N/A
IPC ImpersonateNamedPipeClient N/A N/A
IPC PeekNamedPipe N/A N/A
IPC ReadFile (named pipe handle) read (fifo), msgsnd N/A
IPC RevertToSelf N/A N/A
IPC SetNamedPipeHandleState N/A N/A
IPC TransactNamedPipe N/A N/A WriteFile; ReadFile
IPC WriteFile (named pipe handle) write (fifo), msgrcv N/A
Misc. GetComputerName uname N/A
Misc. SetComputerName N/A N/A
Security SetNamedPipeIdentity Use directory sticky bit N/A

4. Misc
4.1 Security
Subject Windows UNIX Comments
Security AddAccessAllowedAce chmod, fchmod C library does not support security
 
Security AddAccessDeniedAce chmod, fchmod
Security AddAuditAce N/A
Security CreatePrivateObjectSecurity N/A
Security DeleteAce chmod, fchmod
Security DestroyPrivateObjectSecurity N/A
Security GetAce stat*, fstat*, lstat
Security GetAclInformation stat*, fstat*, lstat
Security GetFileSecurity stat*, fstat*, lstat
Security GetPrivateObjectSecurity N/A
Security GetSecurityDescriptorDacl stat*, fstat*, lstat
Security GetUserName getlogin
Security InitializeAcl N/A
Security InitializeSecurityDescriptor Umask
Security LookupAccountName getpwnam, getgrnam
Security LookupAccountSid getpwuid, getuid, geteuid
Security N/A getpwend, setpwent, endpwent
Security N/A getgrent, setgrent, endgrent
Security N/A Setuid, seteuid, setreuid
Security N/A Setgid, setegid, setregid
Security OpenProcessToken getgroups, setgroups, initgroups
Security SetFileSecurity chmod*, fchmod
Security SetPrivateObjectSecurity N/A
Security SetSecurityDescriptorDacl Umask
Security SetSecurityDescriptorGroup chown, fchown, lchown
Security SetSecurityDescriptorOwner chown, fchown, lchown
Security SetSecurityDescriptorSacl N/A

4.2 Exception Handling
Subject Windows UNIX C Library
SEH _try – _except Use C library signals Use C library signals
SEH _try – _finally Use C library signals Use C library signals
SEH AbnormalTermination Use C library signals Use C library signals
SEH GetExceptionCode Use C library signals Use C library signals
SEH RaiseException Use C library signals signal, raise
Signals Use _finally block Use C library atexit
Signals Use C library or terminate process kill raise
Signals Use C library Use C library signal
Signals Use SEH, VEH sigemptyset N/A
Signals Use SEH, VEH sigfillset N/A
Signals Use SEH, VEH sigaddset N/A
Signals Use SEH, VEH sigdelset N/A
Signals Use SEH, VEH sigismember N/A
Signals Use SEH, VEH sigprocmask N/A
Signals Use SEH, VEH sigpending N/A
Signals Use SEH, VEH sigaction N/A
Signals Use SEH, VEH sigsetjmp N/A
Signals Use SEH, VEH siglongjmp N/A
Signals Use SEH, VEH sigsuspendf N/A
Signals Use SEH, VEH psignal N/A
Signals Use SEH, VEH, or C library Use C library abort
Note: Many UNIX vendors provide proprietary exception handling capabilities.

4.3 System Information & Time
Subject Windows
UNIX C Library Comments
System Info GetDiskFreeSpace N/A N/A
System Info GetSystemInfo getrusage N/A
System Info GetVersion uname N/A
System Info GetVolumeInformation N/A N/A
System Info GlobalMemoryStatus getrlimit N/A
System Info Various defined constants sysconf, pathconf, fpathconf N/A
Time GetSystemTime Use C library time, gmtime
Time See ls program,
Use C library asctime
Time CompareFileTime Use C library difftime Compare "calendar" times
Time FileTimeToLocalFileTime, FileTimeToSystemTime Use C library localtime
Time FileTimeToSystemTime Use C library gmtime
Time GetLocalTime Use C library time, localtime
Time See touch program,
Use C library strftime
Time SetLocalTime N/A N/A
Time SetSystemTime N/A N/A
Time Subtract file times Use C library difftime
Time SystemTimeToFileTime Use C library mktime

 

'Programing > C' 카테고리의 다른 글

bzero와 bcopy 윈도우에서 쓰기  (0) 2015.05.22
unix의 drand48()와 srand48() windows에서 사용하기  (0) 2015.05.22
Posted by duehd88
,

Unix                              ->        windows

srand48( (long)time(NULL) );    ->        srand((long)time(NULL));
drand48();                              ->        double(rand())/RAND_MAX;

 

아래에  drand48();        ->        double(rand())/(RAND_MAX+1.0); 이 맞는 거 같다는 말도 있는데 일단 급하니 쓰고봐야겠다...

 

링크 : https://social.msdn.microsoft.com/Forums/vstudio/en-US/9356f151-51d2-412d-8889-d53230cc6ec9/porting-srand48-and-drand48-of-unix-like-platform-based-source?forum=vclanguage

 

 

아래는 github에서 rand48과 srand48을 opensource로 공개한 소스이다.

링크 : https://gist.github.com/mortennobel/8665258

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define RAND48_SEED_0   (0x330e)
#define RAND48_SEED_1 (0xabcd)
#define RAND48_SEED_2 (0x1234)
#define RAND48_MULT_0 (0xe66d)
#define RAND48_MULT_1 (0xdeec)
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
 
unsigned short _rand48_seed[3= {
        RAND48_SEED_0,
         RAND48_SEED_1,
         RAND48_SEED_2
};
 
unsigned short _rand48_mult[3= {
         RAND48_MULT_0,
         RAND48_MULT_1,
         RAND48_MULT_2
 };
 
unsigned short _rand48_add = RAND48_ADD;
 
void _dorand48(unsigned short xseed[3])
{
             unsigned long accu;
             unsigned short temp[2];
 
             accu = (unsigned long)_rand48_mult[0* (unsigned long)xseed[0+
              (unsigned long)_rand48_add;
             temp[0= (unsigned short)accu;        /* lower 16 bits */
             accu >>= sizeof(unsigned short)* 8;
             accu += (unsigned long)_rand48_mult[0* (unsigned long)xseed[1+
              (unsigned long)_rand48_mult[1* (unsigned long)xseed[0];
             temp[1= (unsigned short)accu;        /* middle 16 bits */
             accu >>= sizeof(unsigned short)* 8;
             accu += _rand48_mult[0* xseed[2+ _rand48_mult[1* xseed[1+ _rand48_mult[2* xseed[0];
             xseed[0= temp[0];
             xseed[1= temp[1];
             xseed[2= (unsigned short)accu;
}
 
double erand48(unsigned short xseed[3])
{
         _dorand48(xseed);
         return ldexp((double) xseed[0], -48+
                ldexp((double) xseed[1], -32+
                ldexp((double) xseed[2], -16);
}
 
double drand48(){
    return erand48(_rand48_seed);
}
 
void srand48(long seed){
    _rand48_seed[0= RAND48_SEED_0;
    _rand48_seed[1= (unsigned short)seed;
    _rand48_seed[2= (unsigned short)(seed >> 16);
    _rand48_mult[0= RAND48_MULT_0;
    _rand48_mult[1= RAND48_MULT_1;
    _rand48_mult[2= RAND48_MULT_2;
    _rand48_add = RAND48_ADD;
}
 
cs

 

'Programing > C' 카테고리의 다른 글

bzero와 bcopy 윈도우에서 쓰기  (0) 2015.05.22
Windows, Unix and ANSI C API Comparison  (0) 2015.05.22
Posted by duehd88
,

1. PC에 안드로이드 포팅한다.

2. PC에서 가상머신으로 안드로이드 실행(블루스택, 제니모션, vm ware, virtual machine등등)

3. 모비즌이나 screencast같은 툴로 안드로이드 화면을 pc로 전송하여 컨트롤

4. 리눅스 사용자라면 안드로이드 플랫폼을 올려 사용

 

각각 장단점과 용도가 다르다.

하려고 시도중이라면 얼추 뭐가 장단점이 될지 2번이나 2번의 용도 차이가 뭔지 등등은 다알고 시도하는거라 생각하니 패스

 

안드로이드 소스로 이미지 만들기 귀찮으면 여기가서 다운로드 ㄱㄱ

http://www.android-x86.org/

http://www.android-x86.org/download

 

블루스택 - www.bluestacks.com/

제니모션 - https://www.genymotion.com/

virtual box - https://www.virtualbox.org/

vm ware - http://www.vmware.com/

모비즌 - http://www.mobizen.com/

 

단순히 가상머신 포팅의 경우 virtual box보단 vm ware가 좀 더 가벼운 느낌이 든다. mem부터 가볍게 먹고 들어감.

더 가벼운걸 원한다면 구글링 해보면 이 외에도 검증되진 않았지만 더 가벼운 툴들이 많으니 검색해서 사용해보셈

Posted by duehd88
,

랜덤한 값을 뽑아내는데 쉽고 간편하게 쓸 수 있는 방법이 자바에서 제공해주는 랜덤함수를 쓰는 것이다.

크게 2가지를 이용할 수 있다.

 

첫번째, Random Class 이용하기

1
2
3
4
5
6
7
8
9
10
11
12
13
package{
  public class {
    public static void main(String arg[]) {
      Random random=new Random();
 
      System.out.println(random.nextInt());
      System.out.println(random.nextInt(10));
      System.out.println(random.nextBoolean());
      System.out.println(random.nextDouble());
    }
  }
}
 

 

두번째, Math Class이용하기

1
2
3
4
5
6
7
8
9
package{
  public class {
    public static void main(String arg[]) {
        int random=(int)(Math.random()*100)+1;
        System.out.println(random);
    }
  }
}
 

Math.random()으로 정수형 랜덤을 뽑아내는 경우 double인 반환값을 정수형 형변환을 통해 소수점을 잘라주는게 포인트 입니다. 

 

정수형의 경우 편하게 계산하기 위해 일반화시켜봤는데요.(물론 별거아니지만...)

new Random().nextInt(MaxValue-MinValue+1)+MinValue

(int)(Math.random()*MaxValue-MinValue+1)+MinValue

 

Random Class와 Math Class는 각기 다른 용도가 있습니다. 저의 경우 Random Class만 이용하는 편인데 살펴보다보니 random값을 자주 뽑을 필요가 없고 또한 다양한 형태로 뽑을 필요가 없다면 Math 클래스로 static한 random 메서드를 이용하는게 좀 더 효율적일수도 있을거 같다는 생각이 들기도하네요.

Posted by duehd88
,

stream read하기

Programing/java 2015. 2. 18. 01:47

inputStream을 읽을때 필요한 데이터를 모두 읽을때까지 대기하는 코드

result값으로 1024byte이하의 데이터가 전송되고 스트림이 종료되는 시나리오까지 고려한 코드

네트워크 스트림에서 주로 쓰이는 방법이다.

1
2
3
4
5
6
7
8
9
10
static final int BYTE_SIZE=1024;
int bytesRead=0;
int bytesToRead=BYTE_SIZE;
byte[] input=new byte[bytesToRead];
 
while(bytesRead<bytesToRead){
    int result=in.read(input,bytesRead,bytesToRead-bytesRead);
    if(result==-1){ break; }
    bytesRead+=result;
}

대기없이 inputStream이 한번에 읽을 수 있는 최소한의 byte수만큼만 읽기

조심해서 써야한다. available()같은 경우 stream의 끝에 이를 경우 0을 반환하기 때문에 이렇게 쓰이기 보단 stream이 남아 있는지 여부를 판단하고

없을 경우 stream을 사용할 수 있게 비워주는 식의 코드를 짜야하는 경우 사용하는 것이 좋다.

1
2
3
int bytesToRead=in.available();
byte[] input=new byte[bytesToRead];
in.read(input,0,bytesToRead);

 

Posted by duehd88
,

  우리의 컴퓨터는 고유한 주소를 가지고 있습니다. 바로 internet protocol인데 ip라고 줄여말합니다. 그러니까 컴퓨터간의 고유한 주소라고 볼 수 있습니다. 즉, ip덕분에 네트워크상에서 통신하기를 원하는 컴퓨터를 찾아 통신할 수 있도록 routing 할 수 있게 되는 것이죠.

 

  이러한 ip는 전세계적으로 동일하게 컴퓨터마다 할당하여 관리되어 지는데 각 나라의 공인기관에서 ip를 할당하고 관리합니다. 우리나라의 경우 KISA(한국인터넷진흥원)에서 담당하고 있습니다. 그리고 여기서 ip를 ISP(Internet service provider; SK브로드밴드, olleh KT, LG U+)가 부여받아 우리에게 제공을 해줍니다. 우리는 이 곳에 가입을 하고 모뎀을 통해 각 컴퓨터에게 ip를 제공받고 인터넷을 이용하게 되는 거죠.

 

  일반적으로 IPv4(Internet Protocol Version 4)가 이용되고 있고 3자리 숫자가 4마디씩 있고 이 ip는 32bit 주소체계로 2^32개의 주소를 부여 가능합니다. 현재 ip가 거의 포화된 상태라 IPv6(Internet Protocol Version 6)가 나왔고 표현식은 128bit의 2진수를 16bit단위로 나누어 16진수 변환 후 콜론으로 구분을 하면된다고 합니다. 총 128bit 주소체계로 2^128개의 주소 부여가 가능합니다. 하지만 아직 IPv4가 여전히 대부분을 이루고 있습니다.

 

  IP는 유동IP와 고정IP의 개념이 있습니다. 고정IP는 IP가 고정되어 있어서 변경되지 않습니다. 이는 서버같은 무언가 서비스를 제공하기위한 용도일 경우 주소가 변하면 되지 않으므로 이용합니다. 보안성이 우수하고 유동IP에 비해 가격이 비쌉니다. 서비스를 제공하는 곳에서는 대부분 이 고정 ip를 이용합니다. 유동ip는 인터넷을 접속하면 사용자에게 그때 그때 사용되지 않는 ip를 할당해주는 방식으로 운영이 됩니다. 모든 사용자들이 동시에 인터넷을 접속하지 않기 때문에 가능한 방법입니다. ip주소 부여의 경우 대부분 모뎀에서 이루어지며 공유기를 쓰신다면 기본적으로 내부 사설ip도 유동ip 형식의 운영이 됩니다.

 

  공인IP는 각 사용자들이 ISP로 부터 부여받는 IP를 말합니다. 여기서 유동IP와 고정IP개념을 생각 할 수 있습니다. 가정에서의 경우엔 늘접속하는 경우가 없습니다. 그래서 일반적으로 유동IP를 부여받아 이용합니다. 하지만 기업같은 경우 서비스를 제공해야하기 때문에 고정IP를 부여받아 이용합니다. 사설IP는 공유기같은 장비를 통해 부여받는 IP를 말합니다. 이 또한 대부분의 장비들이 기본적으로 유동IP형식으로 할당합니다. 그리고 설정을 통해 특정 MAC주소나 사용자계정에 고정IP 할당을 해주는 옵션을 제공해줍니다.

 

내 공인 ip를 알고 싶다면 접속해보자 : http://ipconfig.kr/

Posted by duehd88
,