📄 dsocket.cpp
字号:
////////////////////////////////////////////////////////////////////////////
// DSocket.cpp
// Details : Datagram Socket for communication
//
//
// *** Control Packet Format ***
// Type : 1 byte
// Length of hostname : 1 byte
// Hostname : <var>
//
// *** Text packet format ***
// Type : 1 byte
// Length of hostname : 1 byte
// Hostname : < var>
// Length of message : 2 byte
// Message : <var>
//
// *** Audio packet format ***
// Type : 1 byte
// Length of hostname : 1 byte
// Hostname : < var>
// size of audio data : 2 byte
// Audio data : <var>
//
// *** Video packet format ***
// Type : 1 byte
// Length of hostname : 1 byte
// Hostname : < var>
// size of video data : 2 byte
// Video data : <var>
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "VideoNet2.h"
#include "DSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DSocket
// Initialize static members...
CString DSocket::remoteaddress=_T("");
DSocket::DSocket()
{
}
DSocket::~DSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(DSocket, CSocket)
//{{AFX_MSG_MAP(DSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// DSocket 成员函数
//
// 在指定的端口 生成数据报 socket。
// @param port——Port on which datagram socket is created
// @param type——type indicates the purpose of this socket
// which can be control, text, audio or video.
//
// 生成设计报socket,并将socket类型返回到 type.
void DSocket::CreateSocket(int port,int dtype)
{
this->Create(port,SOCK_DGRAM);
type=dtype;
}
// 当远程主机的任何数据到达时被调用
void DSocket::OnReceive(int errcode)
{
}
// 发送控制数据到远程主机
void DSocket::SendControlMessage(int type,LPCTSTR address)
{
char data[1000];
int n = 1;
data[0]=type;
SendTo(data,n+2,PORT_CONTROL,remoteaddress);
}
// 关闭socket
void DSocket::CloseSocket()
{
DSocket::Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -