본문 바로가기

전공 과목 시험정리/C 프로그래밍

(10)
모듈용 윈도우 C 소켓 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#include #pragma comment(lib,"ws2_32.lib") #define BUFSIZE 1024 int senddata(int PORT, char IP[],char data[]); int main() { /* int senddata( int PORT, char IP[], char data[] ); 에러가 없으면 0 반환. 에러 발생 시 에러값 반환. (int 형) */ if (0 != senddata(80, "221.151.187.115", "GET / HTTP/1.1\nHost:www.kim82536.p..
윈도우 C 소켓 기본 자료참고: http://dakuo.tistory.com/159 1234567891011121314151617181920212223242526272829303132333435363738#include #include #include #include #pragma comment(lib,"ws2_32.lib") #define IP "221.151.187.115"#define PORT 80#define BUFSIZE 1024 int main() { WSADATA wsaData; SOCKET client; SOCKADDR_IN serveraddr; char buf[BUFSIZE]; WSAStartup(MAKEWORD(2, 2), &wsaData); printf("WSAStartup : %d\n", WSAGetLa..
C와 C++ 동시사용 12345678910#include #include using namespace std; int main() { printf("test\n"); cout
C++ 에서의 소켓프로그래밍 출처 http://lilyiu.tistory.com/entry/%EC%9C%88%EB%8F%84%EC%9A%B0-%EC%86%8C%EC%BC%93%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-C // WinServer.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다. // #include "stdafx.h"#include #include #include #define PORT 9999 void ErrorHandling(char* message); int _tmain(int argc, char** argv) { WSADATA wsaData; SOCKET hServSock; SOCKET hClntSock; SOCKADDR_IN servAddr; SOCKADDR_I..
Fate 서버 소스 (미완성) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157#include #include #include #include..
fork 로 프로세스 생성 후, 프로세스간 변수 공유 fork() 로 자식 프로세스를 생성한 후에, 자식프로세스에서 배열에 1을 더하고, 부모프로세스에서 그것을 출력한다. .. 인 프로그램에서, 이상하게도 자식 프로세스에서 연산한 값이 부모프로세스에게 전달되지 않았다. -->fork() 로 프로세스를 생성하면, 자식 프로세스와 부모 프로세스 두개의 프로세스를 제어하게 된다. 이때 각각 프로세스는 변수를 복사 한 것처럼 관리되어 지는데, 한 프로세스에서 (자식 프로세스에서 라고 가정할 때) 배열의 값을 수정하고 다른 프로세스에서 그것을 출력한다면 각자 다른 변수인데 값만 같을 뿐이므로, 다른 프로세스에서 출력한 값이 변했을 리가 없다. 따라서 변수를 수정하고 나서 그 값을 공유하고 싶다면 다른 방법을 사용해야 하는데, 첫 번째로 공유메모리를 사용하는 방법이 ..
웹에서 서버정보 파싱 전에 올렸었던http://blog.kim82536.pe.kr/entry/%EC%9B%B9-%EC%9D%91%EB%8B%B5%EC%97%90%EC%84%9C-%EC%84%9C%EB%B2%84-%EC%A0%95%EB%B3%B4-%EC%B6%94%EC%B6%9C 의 프로그램을 약간 수정해 보았다. 원래 소스project.c1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091..
쓰레드 프로그램 서버 소스를 멀티 쓰레드로 돌리기 위해 가져온 예제이다. 이상하게 예제 그대로도 컴파일이 되지 않길래 찾아봤더니쓰레드를 이용한 프로그램의 컴파일은 gcc 에 lpthread 옵션을 줘야 한다고 되어 있었다..http://stackoverflow.com/questions/9331863/lpthread-option-of-gcc 1234567891011121314151617181920212223242526272829303132333435363738#include #include #include #include #include #include // gcc test.c -o test -lpthread void* My(void* Para){ int i; for(i=0;i