資源簡介
網絡電話,可參考,socket編程,簡單實用
代碼片段和文件信息
//?BvSocket.cpp:?implementation?of?the?CBvSocket?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“Phone.h“
#include?“BvSocket.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
#pragma?comment(lib?“wsock32“)
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBvSocket::CBvSocket()
{
}
CBvSocket::~CBvSocket()
{
}
void?CBvSocket::ReportWinsockErr(LPSTR?lpszErrorMsg)
{
char?chMsgBuffer[100];
wsprintf(chMsgBuffer?“\nWinsock?error?%d:?%s\n\n“?WSAGetLastError()?lpszErrorMsg);
MessageBox(NULLchMsgBuffer??AfxGetAppName()?MB_OK|MB_IConstop);
return;???
}
BOOL?CBvSocket::Init(WSADATA*?wsaData)
{
if?(WSAStartup(WINSOCK_VERSIONwsaData))
{
MessageBeep(MB_IConstop);
MessageBox(NULL“Winsock?could?not?be?initialized!“?AfxGetAppName()?MB_OK|MB_IConstop);
????WSACleanup();
????return(FALSE);
}??????????????????
return?TRUE;
}
BOOL?CBvSocket::Clean()
{
int?iErrorCode;
char?chMsgBuffer[100];
if?((iErrorCode?=?WSACleanup()))
{
wsprintf(chMsgBuffer?“Winsock?error?%d.“?iErrorCode);
MessageBeep(MB_IConstop);
MessageBox(NULL?chMsgBuffer??AfxGetAppName()?MB_OK|MB_IConstop);???
return?FALSE;
????}
return?TRUE;
}
BOOL?CBvSocket::GetHostName(char?*name?int?namelen)
//determine?if?the?local?machine?is?on_line!
{
if?(gethostname(name?namelen))
{
ReportWinsockErr(“\nCould?not?resolve?local?host!\nAre?you?on-line?\n“);
return?FALSE;
}
return?TRUE;
}
BOOL?CBvSocket::Create()
//Create?the?default?socket?for?general?use!
{
m_hSocket=socket(PF_INET?SOCK_STREAM?0);
if?(m_hSocket?==?INVALID_SOCKET)
{
ReportWinsockErr(“Could?not?create?server?socket.“);
return?FALSE;
}
return?TRUE;
}
BOOL?CBvSocket::Create(int?af?int?type?int?protocol)
//you?can?create?the?socket?using?the?socketthere?is?equal!
{
m_hSocket=socket(aftypeprotocol);
if?(m_hSocket?==?INVALID_SOCKET)
{
ReportWinsockErr(“Could?not?create?server?socket.“);
return?FALSE;
}
return?TRUE;
}
void?CBvSocket::SetAddrIn(const?char?FAR*?ip?unsigned?short?port)
//you?can?set?you?socket?address?using?the?doted?string?format.
{
m_addrSocket.sin_family=AF_INET;
m_addrSocket.sin_addr.S_un.S_addr=inet_addr(ip);
m_addrSocket.sin_port=htons(port);
}
void?CBvSocket::SetAddrIn(unsigned?short?port)
//you?can?also?let?the?windows?to?process?the?ipif?your?machine?have
//more?than?one?ip.
{
m_addrSocket.sin_family=AF_INET;
m_addrSocket.sin_addr.S_un.S_addr=INADDR_ANY;
m_addrSocket.sin_port=htons(port);
}
BOOL?CBvSocket::Bind()
//if?you?have?used?SetAddrIn()?create?the?socket?addressyou?can?call
//this?default?bind?function?to?name?the?unnamed?socket?address.
{
if?(bind(m_hSocket(LPSOCKADDR)&m_addrSocke
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-12-11?00:02??Phone(音頻)\
?????文件????????5821??2001-07-18?01:17??Phone(音頻)\BvSocket.cpp
?????文件????????1971??2001-07-18?01:17??Phone(音頻)\BvSocket.h
?????文件???????17452??2013-04-30?01:51??Phone(音頻)\Compression.cpp
?????文件????????2036??2013-04-29?17:31??Phone(音頻)\Compression.h
?????目錄???????????0??2013-12-11?00:15??Phone(音頻)\Debug\
?????文件????????6876??2013-05-17?09:58??Phone(音頻)\Debug\BuildLog.htm
?????文件???????42008??2013-05-12?22:01??Phone(音頻)\Debug\Compression.obj
?????文件???????23098??2013-05-12?22:01??Phone(音頻)\Debug\IPAddress.obj
?????文件??????126976??2013-05-17?09:58??Phone(音頻)\Debug\Phone.exe
?????文件?????????920??2013-05-12?22:01??Phone(音頻)\Debug\Phone.exe.em
?????文件?????????984??2013-05-12?22:01??Phone(音頻)\Debug\Phone.exe.em
?????文件?????????861??2013-05-17?09:58??Phone(音頻)\Debug\Phone.exe.intermediate.manifest
?????文件?????1393448??2013-05-17?09:58??Phone(音頻)\Debug\Phone.ilk
?????文件???????22723??2013-05-16?15:18??Phone(音頻)\Debug\Phone.obj
?????文件????25296896??2013-05-12?22:01??Phone(音頻)\Debug\Phone.pch
?????文件?????3730432??2013-05-17?09:58??Phone(音頻)\Debug\Phone.pdb
?????文件????????3732??2013-05-12?22:01??Phone(音頻)\Debug\Phone.res
?????文件???????83353??2013-05-17?09:58??Phone(音頻)\Debug\PhoneDlg.obj
?????文件???????18927??2013-05-16?15:18??Phone(音頻)\Debug\SoundIn.obj
?????文件???????17815??2013-05-12?22:01??Phone(音頻)\Debug\SoundOut.obj
?????文件??????465339??2013-05-12?22:01??Phone(音頻)\Debug\StdAfx.obj
?????文件??????????67??2013-05-17?09:58??Phone(音頻)\Debug\mt.dep
?????文件??????953344??2013-05-17?09:58??Phone(音頻)\Debug\vc90.idb
?????文件?????2011136??2013-05-17?09:58??Phone(音頻)\Debug\vc90.pdb
?????文件????????1672??2013-04-29?14:52??Phone(音頻)\IPAddress.cpp
?????文件????????1324??2013-04-29?14:52??Phone(音頻)\IPAddress.h
?????文件???????23812??2013-05-11?22:57??Phone(音頻)\Phone.aps
?????文件????????1800??2001-07-18?01:17??Phone(音頻)\Phone.clw
?????文件????????2049??2001-07-18?01:17??Phone(音頻)\Phone.cpp
?????文件????????4791??2001-07-18?01:17??Phone(音頻)\Phone.dsp
............此處省略26個文件信息
- 上一篇:cmake-3.8.2
- 下一篇:MFC 子對話框向父對話框 Edit內容的同步
評論
共有 條評論