==========================================================================================
NETWORK
==========================================================================================
<NETWORK>
http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site
• 리눅스 네트워크 프로그래밍
• 네트워크 프로그래밍 기초 문서들
• 예제로 알아보는 소켓 프로그래밍
=소켓프로그래밍


=socket() - 소켓 번호 만드는 함수
클라이언트(크롬...) 서버(벽)(구글...)
SC모델 -> SERVER(서비스 제공-하인) - CLIENT(고객)
SOCKET(2) Linux Programmer's Manual SOCKET(2)
NAME
socket - create an endpoint for communication
SYNOPSIS
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
DESCRIPTION
socket() creates an endpoint for communication and returns a descrip‐
tor.
The domain argument specifies a communication domain; this selects the
protocol family which will be used for communication. These families
are defined in <sys/socket.h>. The currently understood formats
include:
Name Purpose Man page
AF_UNIX, AF_LOCAL Local communication unix(7)
AF_INET IPv4 Internet protocols ip(7)
AF_INET6 IPv6 Internet protocols ipv6(7)
AF_IPX IPX - Novell protocols
AF_NETLINK Kernel user interface device netlink(7)
AF_X25 ITU-T X.25 / ISO-8208 protocol x25(7)
AF_AX25 Amateur radio AX.25 protocol
AF_ATMPVC Access to raw ATM PVCs
AF_APPLETALK Appletalk ddp(7)
AF_PACKET Low level packet interface packet(7)
The socket has the indicated type, which specifies the communication
semantics. Currently defined types are:
SOCK_STREAM Provides sequenced, reliable, two-way, connection-based
byte streams. An out-of-band data transmission mecha‐
nism may be supported.
SOCK_DGRAM Supports datagrams (connectionless, unreliable messages
of a fixed maximum length).
SOCK_SEQPACKET Provides a sequenced, reliable, two-way connection-
based data transmission path for datagrams of fixed
RETURN VALUE
On success, a file descriptor (저수준) for the new socket is returned. On
error, -1 is returned, and errno is set appropriately.


=grep
-찾고싶은 문자열에 "" - 띄어쓰기 있는 경우
-r : 하위디렉토리까지 검색


GREP(1) GREP(1)
NAME
grep, egrep, fgrep, rgrep - print lines matching a pattern
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
DESCRIPTION
grep searches the named input FILEs (or standard input if no files are
named, or if a single hyphen-minus (-) is given as file name) for lines
containing a match to the given PATTERN. By default, grep prints the
matching lines.
In addition, three variant programs egrep, fgrep and rgrep are
available. egrep is the same as grep -E. fgrep is the same as
grep -F. rgrep is the same as grep -r. Direct invocation as either
egrep or fgrep is deprecated, but is provided to allow historical
applications that rely on them to run unmodified.
OPTIONS
Generic Program Information
--help Print a usage message briefly summarizing these command-line
options and the bug-reporting address, then exit.
-V, --version
Print the version number of grep to the standard output stream.
This version number should be included in all bug reports (see
below).
Matcher Selection
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see
below). (-E is specified by POSIX.)
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched. (-F is specified by
POSIX.)
-G, --basic-regexp
Interpret PATTERN as a basic regular expression (BRE, see
below). This is the default.
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see
below). This is highly experimental and grep -P may warn of
unimplemented features.
=


=SOCK_STREAM
=


-TCP(TCP/IP)
SOCK_STREAM = 1, /* Sequenced, reliable, connection-based
byte streams. */
-UDP(UDP/IP...-> 노래.. 영화감상...)
SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams
of fixed maximum length. */
==NETWORK
=IPC -Inter Process Comunication ( 내부에서 대화 )
창 <-Data-> 창
실행 - 프로세스 프로세스
=NETWORK - 다른 PC 간
하드 - 프로그램
=IPC의 일부 => PIPE
=PF_UNIX => IPC로 동작 (UNIX슈퍼컴퓨터에 단말기가 붙어서 있었음)-> IPC
=X.25 => 화상회의
=ATM=> 중계기(고속)
=유닉스 - 헤더파일 존재함
=WINDOWS에서는 헤더파일 존재하지 않는 경우 있음 (생으로 써줘야함)
#define SOCK_DGRAM SOCK_DGRAM
SOCK_RAW = 3, /* Raw protocol interface. *///가공X - (틀(봉투)만 만들고 내용(주소)은 안채워넣음)
#define SOCK_RAW SOCK_RAW
SOCK_RDM = 4, /* Reliably-delivered messages. */
#define SOCK_RDM SOCK_RDM
SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based,
datagrams of fixed maximum length. */
#define SOCK_SEQPACKET SOCK_SEQPACKET
SOCK_DCCP = 6, /* Datagram Congestion Control Protocol. */
#define SOCK_DCCP SOCK_DCCP
SOCK_PACKET = 10, /* Linux specific way of getting packets
at the dev level. For writing rarp and
other similar things on the user level. */
#define SOCK_PACKET SOCK_PACKET
/* Flags to be ORed into the type parameter of socket and socketpair and
used for the flags parameter of paccept. */
SOCK_CLOEXEC = 02000000, /* Atomically set close-on-exec flag for the
new descriptor(s). */
#define SOCK_CLOEXEC SOCK_CLOEXEC
SOCK_NONBLOCK = 04000 /* Atomically mark descriptor(s) as
non-blocking. */
#define SOCK_NONBLOCK SOCK_NONBLOCK
=
1. 연결 작업 -
2. 데이터 교환 - READ / WRITE
3. 해제 작업 - CLOSE
=
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
int main() { printf("errno : %d\n",errno); open("kkkk", O_RDONLY); printf("errno : %d\n",errno);
return 0; } |


=perror
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
int main() { printf("errno : %d\n",errno); open("kkkk", O_RDONLY); printf("errno : %d\n",errno); errno = EADDRINUSE; perror("smart"); return 0; } |




=
==========================================================================================
C#
==========================================================================================
<C#>
=FILEINFO
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO;
namespace FILE08_filefind { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { lstView.Clear(); lstView.View = View.Details; lstView.CheckBoxes = true; lstView.FullRowSelect = true; lstView.GridLines = true; lstView.Sorting = SortOrder.Ascending; lstView.Columns.Add("파일명", 170, HorizontalAlignment.Left); lstView.Columns.Add("파일크기", 80, HorizontalAlignment.Right); lstView.Columns.Add("수정일자", 150, HorizontalAlignment.Left); }
void FindFile(string str) { string dir = txt_dir.Text.Trim(); if(dir=="") { MessageBox.Show("검색디렉토리를 입력하세요!"); return; } string[] files_list; files_list = Directory.GetFiles(dir, str); for(int i=0; i < files_list.Length;++i) { ListViewItem item1 = new ListViewItem(files_list[i], 0);
var info = new FileInfo(item1.Text);//from file in Directory.GetFiles(item1.Text)//@item1.Text item1.SubItems.Add(info.Length.ToString()); item1.SubItems.Add(info.LastWriteTime.ToString()); lstView.Items.Add(item1); } }
private void btn_search_Click(object sender, EventArgs e) { if(txt_filename.Text != "") { lstView.Items.Clear(); FindFile(txt_filename.Text); } } } } |


=NETWORK


=65535(장비별로 달라짐) => PORT개수(문 없는 상태)
=문(출구, 입구 , 출입구) 생성 => 소켓
=DNS
-nslookup


=

=

-
using System; using System.Net;
namespace network { class Program { static void Main(string[] args) { IPAddress ex1 = IPAddress.Parse("192.168.0.169"); IPAddress ex2 = IPAddress.Any; IPAddress ex3 = IPAddress.Broadcast; IPAddress ex4 = IPAddress.Loopback; IPAddress ex5 = IPAddress.None;
Console.WriteLine("{0}={1}", "ex1", ex1); Console.WriteLine("{0}={1}", "ex2(Any)", ex2); Console.WriteLine("{0}={1}", "ex3(Broadcast)", ex3); Console.WriteLine("{0}={1}", "ex4(Loopback)", ex4); Console.WriteLine("{0}={1}", "ex5(None)", ex5); } } } |


=

using System; using System.Net;
namespace network2 { class Program { static void Main(string[] args) { IPAddress ex = IPAddress.Parse("192.168.0.169"); IPEndPoint ie = new IPEndPoint(ex, 8000); // 로컬주소를 바인드하거나 소켓과 원격주소를 연결시 사용 Console.WriteLine("ToString() :{0}", ie.ToString()); Console.WriteLine("AddressFamily :{0}", ie.AddressFamily); Console.WriteLine("Address :{0}", ie.Port); Console.WriteLine("MaxPort() :{0} MinPort() :{1}", IPEndPoint.MaxPort, IPEndPoint.MinPort); } } } |


=


=복사기 ...(렌케이블 장비)

=
=별로 사용은 안함

=Buffered CLASS (읽기, 파일) => 대용량처리
- Flush()

=

=