-
大小: 75KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-06-13
- 語(yǔ)言: C/C++
- 標(biāo)簽: c++??mfc??網(wǎng)絡(luò)電話??網(wǎng)絡(luò)語(yǔ)音??
資源簡(jiǎn)介
用c++/mfc編寫的網(wǎng)絡(luò)電話例程,可以連接本機(jī)做測(cè)試!

代碼片段和文件信息
//?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
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5821??2001-07-18?01:17??netPhone\BvSocket.cpp
?????文件???????1971??2001-07-18?01:17??netPhone\BvSocket.h
?????文件??????15675??2001-07-18?01:17??netPhone\Compression.cpp
?????文件???????1854??2001-07-18?01:17??netPhone\Compression.h
?????文件???????1377??2001-07-18?01:17??netPhone\IPAddress.cpp
?????文件???????1239??2001-07-18?01:17??netPhone\IPAddress.h
?????文件??????22908??2001-07-18?01:17??netPhone\Phone.aps
?????文件???????1800??2001-07-18?01:17??netPhone\Phone.clw
?????文件???????2049??2001-07-18?01:17??netPhone\Phone.cpp
?????文件???????4791??2001-07-18?01:17??netPhone\Phone.dsp
?????文件????????533??2001-07-18?01:17??netPhone\Phone.dsw
?????文件???????1313??2001-07-18?01:17??netPhone\Phone.h
?????文件?????181248??2003-06-11?17:36??netPhone\Phone.ncb
?????文件??????56832??2003-06-11?17:36??netPhone\Phone.opt
?????文件???????2433??2003-06-11?17:36??netPhone\Phone.plg
?????文件???????7172??2001-07-18?01:17??netPhone\Phone.rc
?????文件??????36864??2001-07-18?01:17??netPhone\Phone1.exe
?????文件??????13028??2001-07-18?01:17??netPhone\PhoneDlg.cpp
?????文件???????2645??2001-07-18?01:17??netPhone\PhoneDlg.h
?????文件?????????65??2001-07-18?01:17??netPhone\ReadMe.txt
?????文件???????1388??2001-07-18?01:17??netPhone\resource.h
?????文件???????6547??2001-07-18?01:17??netPhone\SoundIn.cpp
?????文件???????1863??2001-07-18?01:17??netPhone\SoundIn.h
?????文件???????6001??2001-07-18?01:17??netPhone\SoundOut.cpp
?????文件???????1398??2001-07-18?01:17??netPhone\SoundOut.h
?????文件????????207??2001-07-18?01:17??netPhone\StdAfx.cpp
?????文件???????1054??2001-07-18?01:17??netPhone\StdAfx.h
?????文件????????766??2001-07-18?01:17??netPhone\res\icon1.ico
?????文件???????1078??2001-07-18?01:17??netPhone\res\Phone.ico
?????文件????????397??2001-07-18?01:17??netPhone\res\Phone.rc2
............此處省略6個(gè)文件信息
評(píng)論
共有 條評(píng)論