资源简介
用c++/mfc编写的网络电话例程,可以连接本机做测试!
代码片段和文件信息
// 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 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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个文件信息
相关资源
- C++头文件转delphi工具 + 源码
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- 基于mfc的多线程文件传输
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- MFC数字钟(基于VC6.0)
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- ChartCtrl控件库(可在VS2019中使用)
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
川公网安备 51152502000135号
评论
共有 条评论