• 大小: 13.82MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-18
  • 语言: C/C++
  • 标签: C++  socket  网络电话  

资源简介

网络电话,可参考,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.embed.manifest
     文件         984  2013-05-12 22:01  Phone(音频)\Debug\Phone.exe.embed.manifest.res
     文件         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个文件信息

评论

共有 条评论