CB嶄喘socket api亟利大宥儷殻會
作者 佚名技术
来源 程序设计
浏览
发布时间 2012-06-30
c TThread //Communication Thread { private: SOCKET m_AcceptSocket; char szTmp[256];//ERROR MESSAGE public: __fastcall TCommunication(SOCKET m_Socket,bool CreateSuspended); __fastcall ~TCommunication(); protected: virtual void __fastcall Execute(); }; class TListenThread:public TThread //Listen Thread { private: WSAData wsaData; struct sockaddr_in server; fd_set FDS; UINT m_Port; PROTO m_Protocol; char szTmp[256];//Error Message public: SOCKET m_Socket; void __fastcall DoError(); void __fastcall InitSocket(); void __fastcall CreateListenSocket(); void __fastcall SetListenSocket(); void __fastcall BindListenSocket(); void __fastcall ListenSocket(); public: __fastcall TListenThread(PROTO m_ProtocolA,UINT m_PortA,bool CreateSuspended); virtual __fastcall ~TListenThread(); protected: virtual void __fastcall Execute(); }; extern PACKAGE TPSTNForm *PSTNForm; #endif .cpp File #include <vcl.h> #pragma hdrstop #include "UDPServer.h" #pragma package(smart_init) #pragma resource "*.dfm" TPSTNForm *PSTNForm; TListenThread *pThread=0; //******************************CLASS TCommunication For TCP**************************************************** __fastcall TCommunication::TCommunication(SOCKET m_Socket,bool CreateSuspended):TThread(FALSE) { m_AcceptSocket=m_Socket; szTmp[0]=''\0''; FreeOnTerminate=true; } __fastcall TCommunication::~TCommunication() { // closesocket(m_AcceptSocket); } void __fastcall TCommunication::Execute() { char buf[4096]; int nSize=0; nSize=recv(m_AcceptSocket,(char FAR*)buf,4096,0); if(nSize>0) { buf[nSize]=''\0''; //Display PSTNForm->Memo1->Lines->Add("Received Length:"+String(nSize)); PSTNForm->Memo1->Lines->Add("Received:"+StrPas(buf)); //Deliver ::Sleep(100); send(m_AcceptSocket,buf,nSize,0); } } //******************************CLASS TListenThread***************************************************** __fastcall TListenThread::TListenThread(PROTO m_ProtocolA,UINT m_PortA,bool CreateSuspended):TThread(FALSE) { m_Socket=INVALID_SOCKET; m_Port=m_PortA; m_Protocol=m_ProtocolA; szTmp[0]=''\0''; ::ZeroMemory(&wsaData,sizeof(WSAData)); ::ZeroMemory(&server,sizeof(struct sockaddr_in)); FreeOnTerminate=TRUE;//Automatically delete while terminating. } __fastcall TListenThread::~TListenThread() { closesocket(m_Socket); ::WSACleanup(); m_Socket=INVALID_SOCKET; m_Port=0; m_Protocol=TCP; szTmp[0]=''\0''; ::ZeroMemory(&wsaData,sizeof(WSAData)); ::ZeroMemory(&server,sizeof(struct sockaddr_in)); } void __fastcall TListenThread::DoError() { if(m_Socket!=INVALID_SOCKET) closesocket(m_Socket); WSACl |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: C++Builder调用Matlab下一篇: 用C++Builder获取应用程序图标
关于CB嶄喘socket api亟利大宥儷殻會的所有评论