구조체를 보내도 될꺼 같은데.. 하고 의문이 들어 확신하기 위해 실험 했고 성공함
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 | IOCPClass* IOCP = (IOCPClass*)pParam; DWORD RecvByte; ULONG_PTR upDevKey = 0; DataBox* DB = NULL; while (true) { if (GetQueuedCompletionStatus(IOCP->hIocp, &RecvByte, &upDevKey, (LPOVERLAPPED*)&DB, INFINITE) == false) { cout << "Get Queue Error " << endl; continue; } if (upDevKey == IOKEY_LISTEN) { CreateIoCompletionPort((HANDLE)DB->sock, IOCP->hIocp, IOKEY_CHILD, 0); cout << "New Client : " << inet_ntoa(DB->ClientAddr.sin_addr) << "Connected.. " << endl; EnterCriticalSection(&IOCP->cs); IOCP->set.insert(DB); LeaveCriticalSection(&IOCP->cs); } else if (upDevKey == IOKEY_CHILD) { temp t; memset(&t, '\0', sizeof(t)); memcpy(&t,DB->buf,sizeof(t)); cout << "Client : " << inet_ntoa(DB->ClientAddr.sin_addr) << " ->> " << t.age << t.buf << endl; // cout << "Client : " << inet_ntoa(DB->ClientAddr.sin_addr) << " ->> " << t.age << t.buf << endl; } DWORD Flags = 0; WSABUF wsaBuf; wsaBuf.buf = DB->buf; wsaBuf.len = sizeof(DB->buf); /* Address OR Memoey */ WSARecv(DB->sock, &wsaBuf, 1, NULL, &Flags, DB, NULL); // Event Mapping } | cs |
서버에서 wsaBuf로 받고
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | while (true) { memset(buf, '\0', 200); cout << "Chat : "; char buf[200]; cin >> buf; struct temp t; t.age = 10; strcpy(t.buf, buf); send(sock, (char*)&t, sizeof(t), 0); } | cs |
zz
클라이언트에서 age 와 char형 배열을 가지고 있는 temp라는 구조체를 보내줬음.
정상적으로 됨.
'서버프로그래밍' 카테고리의 다른 글
서버실험용 간단 클라이언트 (0) | 2018.07.12 |
---|---|
WSABUF 에 대한 실험 (0) | 2018.06.27 |
UDP를 이용한 채팅서버 만들기 (0) | 2018.06.24 |
내 머릿속에 남아있는 HANDlE의 의의 (0) | 2018.05.27 |
가변길이 패킷 (0) | 2018.05.27 |