|
TIdTcpServer에다 TIdServerInterceptLogEvent 컴포넌트를 붙여서 접속, 패킷 메시지를 뿌리고 있었는데, 이걸 제거하니까 제대로 작동하네요..
왜 그런지는 모르겠지만요..ㅡ.ㅡ
DoyongID 님이 쓰신 글 :
: 채팅서버에 클라이언트 2대를 물려서 메시지를 주고받고 있습니다..
:
: A클라이언트가 메시지 보내면 서버에서 받아서, A,B에게 전송하고,
: B클라이언트가 메시지에 보내면 역시 서버에서 A,B에게 다시 전송하는 방식인데요..
:
: 각 클라이언트가 1ms마다 메시지를 보냅니다..
:
: 그런데, 이 과정에서 A클라이언트의 접속을 해제하면 B클라이언트 접속도 해제되거든요.. 어디가 문제인지 모르겠습니다. 동기화 문제인가 싶어서 크리티컬섹션도 먹였는데, 마찬가지고..
:
: void __fastcall TWin_Main::TCPServerExecute(TIdContext *AContext)
: {
: TByteDynArray Buffer;
: PACKET_RECVCHAT stRecvPacket;
: PACKET_SENDCHAT stSendPacket;
: BYTE Cmd;
:
: TIdContext *lpContext;
:
: EnterCriticalSection(&Cs);
:
: Cmd = AContext->Connection->IOHandler->ReadChar();
:
: switch(Cmd)
: {
: case CMD_CHAT:
: AContext->Connection->IOHandler->ReadBytes(Buffer, sizeof(PACKET_RECVCHAT), false);
: BytesToRaw(Buffer, &stRecvPacket, sizeof(PACKET_RECVCHAT));
:
: ListBox_Info->ItemIndex = ListBox_Info->Items->Count - 1;
:
: stSendPacket.Cmd = CMD_CHAT;
: strcpy(stSendPacket.Str, stRecvPacket.Str);
:
: Buffer = RawToBytes(&stSendPacket, sizeof(PACKET_SENDCHAT));
:
: TList *LockList = TCPServer->Contexts->LockList();
:
: try
: {
: for(int i = 0; i < LockList->Count; i++)
: {
: lpContext = (TIdContext *)(LockList->Items[i]); // get client-object
:
: if(lpContext->Connection->IOHandler->Connected())
: lpContext->Connection->IOHandler->Write(Buffer);
: }
: }
: __finally
: {
: TCPServer->Contexts->UnlockList();
: LeaveCriticalSection(&Cs);
: }
: }
: }
|