반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- swift6
- nestjs
- RFC1738/1808
- @EnvironmentObject
- dismiss
- subject
- Operater
- @Binding
- Xcode
- NullObject
- vim
- RxCocoa
- Operators
- URL(string:)
- ios14
- @State
- SWIFT
- operator
- typeorm
- graphql
- nonisolated
- Creating Operators
- init?
- init
- RxSwift
- Bug
- IOS
- @Environment
- NavigationLink
- SwiftUI
Archives
- Today
- Total
Tunko Development Diary
[TCP/IP] 윈도우 기반 클라이언트 예제 본문
출처 도서 : [열혈 TCP/IP 소켓 프로그래밍]
Client
#include <stdio.h>#include <stdlib.h>#include <WinSock2.h>void ErrorHandling(char* message);int main(int argc, char* argv[]){WSADATA wsaData;SOCKET hSocket;SOCKADDR_IN servAddr;char message[30];int strLen;if (argc != 3){printf("Usage : %s <IP> <post> \n", argv[0]);exit(1);}if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)ErrorHandling("WSASTartup() error!");hSocket = socket(PF_INET, SOCK_STREAM, 0);if (hSocket == INVALID_SOCKET)ErrorHandling("socket() error");memset(&servAddr, 0, sizeof(servAddr));servAddr.sin_family = AF_INET;servAddr.sin_addr.s_addr = inet_addr(argv[1]);servAddr.sin_port = htons(atoi(argv[2]));if (connect(hSocket, (SOCKADDR*)&servAddr, sizeof(servAddr)) == SOCKET_ERROR)ErrorHandling("connect() error!");if (connect(hSocket, (SOCKADDR*)&servAddr, sizeof(servAddr)) == SOCKET_ERROR)ErrorHandling("connect() error!");strLen = recv(hSocket, message, sizeof(message) - 1, 0);if (strLen == -1)ErrorHandling("read() Error");printf("Message form server : %s \n", message);closesocket(hSocket);WSACleanup();return 0;}void ErrorHandling(char* message){fputs(message, stderr);fputc('\n', stderr);exit(1);}
반응형
'Development > TCP|IP' 카테고리의 다른 글
WInSock 사용시 링커 에러 (1) | 2017.10.01 |
---|---|
[TCP/IP] 윈도우기반 서버 예제 (0) | 2017.09.30 |
Comments