Ejemplo n.º 1
0
/**
*       Send the control data to remote host
*
*
*/
void DSocket::SendControlMessage(int type,char *address)
{
char data[1000];
int n;

	// Prepare the data packet 
	
	// Type of control packet
	data[0]=type;				

	// Length of hostname
	n=strlen(localname);	
	data[1]=n;					
	
	// Name of the sender host
	memcpy(&data[2],localname,n);
	
	
	if(address==NULL)
	{
	
	SendTo(data,n+2,PORT_CONTROL,remoteaddress);
	
	}
	else
	{
	
	SendTo(data,n+2,PORT_CONTROL,address);
	
	}



}
Ejemplo n.º 2
0
/**
 * Realise le parcourt avec la piece courante
 */
void processPiece()
{
    // Attend que la station 1 nous ai donne une piece
    printf("Attend que la station 1 nous ai donne une piece ...\n");
    while(!getPieceReceived())
        waitTime(500);
    
    printf("Attend que la piece soit en place ...\n");
    waitBit(PIECE, TRUE);
    waitTime(1000);
    
    // Regarde si c'est une piece metallique
    pieceMetal = getCapteur(PIECE_METAL);
    if(pieceMetal) {
        printf("--->>> Piece en métal\n");
        SendTo(station_3, ADDR_STATION_3, PORT_LISTEN_3_2, "PIECE_METAL", 11);
    }
    
    // Monte l'ascenseur
    printf("Monte l'ascensseur ...\n");
    setActuateur(ASC_DESCEND, OFF);
    setActuateur(ASC_MONTE, ON);
    waitBit(ASC_HAUT, TRUE);
    setActuateur(ASC_MONTE, OFF);
    
    waitTime(1000);
    
    // Piece noire
    pieceNoire = !getCapteur(HAUTEUR_PIECE);
    if(pieceNoire && !pieceMetal) {
        printf("--->>> Piece noire\n");
        SendTo(station_3, ADDR_STATION_3, PORT_LISTEN_3_2, "PIECE_NOIRE", 11);
    }
    else if(!pieceMetal) {
        printf("--->>> Piece rouge\n");
        SendTo(station_3, ADDR_STATION_3, PORT_LISTEN_3_2, "PIECE_ROUGE", 11);
    }
    
    // Attend que la station 3 soit en reception
    printf("Attend que la station 3 soit prete a recevoir une piece ...\n");
    while(!getCanGivePiece())
        waitTime(500);
    
    // Active le pousseur
    printf("Active le pousseur de piece ...\n");
    setActuateur(PP, ON);
    waitTime(1000);
    setActuateur(PP, OFF);
    
    // Active le coussin
    printf("Active le coussin d'air ...\n");
    setActuateur(COUSSIN_AIR, ON);
    waitTime(2000);
    setActuateur(COUSSIN_AIR, OFF);
    
    // Previens la station 3 qu'on lui donne une piece
    printf("Previens la station 3 qu'on lui donne une piece ...\n");
    SendTo(station_3, ADDR_STATION_3, PORT_LISTEN_3_2, "DONNE_PIECE", 11);
    setCanGivePiece(FALSE);
}
/**
* 发送命令帧
* @param void
* @return void
*/
void CSocketInterfaceCmdSend::SendCommandFrame()
{
	int iCount = 0;
	iCount = SendTo(m_oFrameInterface.m_pFrameData, m_oFrameInterface.m_usFrameSize, m_uiPortAimToLine, m_strIPAim);
	iCount = SendTo(m_oFrameInterface.m_pFrameData, m_oFrameInterface.m_usFrameSize, m_uiPortAimToOperation, m_strIPAim);
	TRACE1("命令帧字节数%d\r\n", iCount);
}
Ejemplo n.º 4
0
/*---------------------------------------------------------
	実行
---------------------------------------------------------*/
void CSaoriIMM::exec(const CSAORIInput& in,CSAORIOutput& out)
{
	out.result_code = SAORIRESULT_BAD_REQUEST;
	if ( in.args.size() < 1 ) { return; }

	DWORD flag = SND_ASYNC;
	std::string filepath;

	if ( wcsnicmp(in.args[0].c_str(),L"list",4) == 0 ) {
		UpdateWindowList();

		if ( m_list.size() == 0 ) {
			out.result_code = SAORIRESULT_NO_CONTENT;
			return;
		}

		out.result_code = SAORIRESULT_OK;

		string_t txt;

		size_t n = m_list.size();
		string_t title;

		for ( size_t i = 0 ; i < n ; ++i ) {
			title = SAORI_FUNC::MultiByteToUnicode(m_list[i].title.c_str());
			out.values.push_back(title);
			txt += title;
			txt += L"\1";
		}

		if ( txt.size() ) {
			txt.erase(txt.size()-1,1);
		}
		out.result = txt;
	}
	else if ( wcsnicmp(in.args[0].c_str(),L"send",4) == 0 ) {
		if ( in.args.size() < 2 ) {
			return;
		}

		const char_t *send_to = NULL;
		if ( in.args.size() >= 3 ) {
			send_to = in.args[2].c_str();
		}
		SendTo(out,in.args[1].c_str(),send_to);
	}
	else if ( wcsnicmp(in.args[0].c_str(),L"focus",5) == 0 ) {
		if ( in.args.size() < 2 ) {
			return;
		}

		const char_t *send_to = NULL;
		if ( in.args.size() >= 3 ) {
			send_to = in.args[1].c_str();
		}
		SendTo(out,L"$TTPC_FOCUS",send_to);
	}
}
Ejemplo n.º 5
0
// 查询仪器误码
//************************************
// Method:    OnQueryErrorCode
// FullName:  CADCSet::OnQueryErrorCode
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
//************************************
void CADCSet::OnQueryErrorCode(void)
{
	int iPos = 0;
	// 广播查询采集站
	iPos = ADCSetFrameHead(BroadCastPort, SendQueryCmd, QueryErrorCodePort);
	OnQueryErrorCodeFdu(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
	// 按IP地址查询交叉站
	iPos = ADCSetFrameHead(IPSetAddrStart, SendQueryCmd, QueryErrorCodePort);
	OnQueryErrorCodeLAUX(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
}
Ejemplo n.º 6
0
// ADC参数设置
//************************************
// Method:    OnADCSet
// FullName:  CADCSet::OnADCSet
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
//************************************
void CADCSet::OnADCSet(void)
{
	unsigned int uiIPAim = 0;
	int iPos = 0;
	uiIPAim = BroadCastPort;
	iPos = ADCSetFrameHead(uiIPAim, true, SendSetCmd, ADSetReturnPort);
	OnSetSine(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	OnStopSample(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	OnOpenPowerTBLow(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	Sleep(ADCOperationSleepTime);

	OnOpenPowerTBHigh(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
	
	Sleep(ADCOperationSleepTime);

	OnOpenSwitchTBLow(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	Sleep(ADCOperationSleepTime);

 	OnOpenSwitchTBHigh(iPos);
 	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
 
 	Sleep(ADCOperationSleepTime);

 	OnStopSample(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	Sleep(ADCOperationSleepTime);
	
 	OnADCRegisterWrite(iPos, false);
 	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
 
 	Sleep(ADCOperationSleepTime);
 
 	OnADCRegisterRead(iPos);
 	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
 
 	Sleep(ADCOperationSleepTime);

	OnADCSetReturn(iPos);
 	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
}
Ejemplo n.º 7
0
//
// 发送指定玩家
//
void CGateServer::OnSendToPlayer(CIOContext *pContext, WORD size)
{
	ProtoGateClient::SendToPlayer requestSendToPlayer;
	ProtoGateServer::SendToPlayer responseSendToPlayer;

	BYTE buffer[PACK_BUFFER_SIZE];
	CCacheBuffer writeBuffer(sizeof(buffer), buffer);

	//
	// 1. 解析消息
	//
	if (Parser(&pContext->GetRecvBuffer(), &requestSendToPlayer, size) == FALSE) {
		return;
	}

	//
	// 2. 转发协议
	//
	if (pContext->guid == 0xffffffff) {
		return;
	}

	responseSendToPlayer.set_size(requestSendToPlayer.size());
	responseSendToPlayer.set_data(requestSendToPlayer.data().c_str(), requestSendToPlayer.size());

	//
	// 3. 序列化消息
	//
	Serializer(&writeBuffer, &responseSendToPlayer, ProtoGateServer::RESPONSE_MSG::SEND_TO_PLAYER);

	//
	// 4. 发送指定玩家
	//
	if (requestSendToPlayer.guids_size() > 0) {
		for (int index = 0; index < requestSendToPlayer.guids_size(); index++) {
			if (CIOContext *pContextSendTo = QueryContext(requestSendToPlayer.guids(index))) {
				if (pContext != pContextSendTo) {
					SendTo(pContextSendTo, buffer, writeBuffer.GetActiveBufferSize());
				}
			}
		}
	}
	else {
		for (PlayerMap::const_iterator itPlayer = m_players.begin(); itPlayer != m_players.end(); ++itPlayer) {
			if (pContext != itPlayer->second) {
				SendTo(itPlayer->second, buffer, writeBuffer.GetActiveBufferSize());
			}
		}
	}
}
Ejemplo n.º 8
0
// 查询仪器误码
//************************************
// Method:    OnQueryErrorCode
// FullName:  CADCSet::OnQueryErrorCode
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
//************************************
void CADCSet::OnQueryErrorCode(void)
{
	unsigned int uiIPAim = 0;
	int iPos = 0;
	// 广播查询采集站
	uiIPAim = BroadCastPort;
	iPos = ADCSetFrameHead(uiIPAim, true, SendQueryCmd, QueryErrorCodePort);
	OnQueryErrorCodeFdu(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
	// 按IP地址查询交叉站
	uiIPAim = IPSetAddrStart;
	iPos = ADCSetFrameHead(uiIPAim, true, SendQueryCmd, QueryErrorCodePort);
	OnQueryErrorCodeLAUX(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
}
Ejemplo n.º 9
0
void Zoo::RegisterNode() {
  MessagePtr msg(new Message());
  msg->set_src(rank());
  msg->set_dst(kController);
  msg->set_type(MsgType::Control_Register);
  msg->Push(Blob(&nodes_[rank()], sizeof(Node)));
  SendTo(actor::kCommunicator, msg);

  // waif for reply
  mailbox_->Pop(msg);
  CHECK(msg->type() == MsgType::Control_Reply_Register);
  CHECK(msg->data().size() == 2);
  Blob info_blob = msg->data()[0];
  Blob count_blob = msg->data()[1];
  num_workers_ = count_blob.As<int>(0);
  num_servers_ = count_blob.As<int>(1);
  worker_id_to_rank_.resize(num_workers_);
  server_id_to_rank_.resize(num_servers_);
  CHECK(info_blob.size() == size() * sizeof(Node));
  memcpy(nodes_.data(), info_blob.data(), info_blob.size());
  for (auto node : nodes_) {
    if (node.worker_id != -1) {
      worker_id_to_rank_[node.worker_id] = node.rank;
    }
    if (node.server_id != -1) {
      server_id_to_rank_[node.server_id] = node.rank;
    }
  }
  Log::Debug("rank %d end register\n", Zoo::Get()->rank());
}
Ejemplo n.º 10
0
int CTCPConnect::GetCustLevel(CString StrCardNum,CString strIP,CString strPort,UINT iOverTime)
{
    if (StartSocket(strPort,strIP))
    {
        char cCardNum[30];
        CCommonConvert::CStringToChar(StrCardNum,cCardNum);
        SocketPackage package = MakePackage(cCardNum);
        int size = sizeof(package);
        SendTo((char*)&package,sizeof(package));
        CString CardNum = _T("cardnum:")+StrCardNum;
        WriteLogWithTime(CardNum);
        char CardRecv[255];
        BOOL RecvTemp = FALSE;
        setsockopt(m_tSocket,SOL_SOCKET,SO_RCVTIMEO,(char *)&iOverTime,sizeof(UINT));
        if (!RecvFrom(CardRecv,255))
        {
            return -1;
        }
        int iLevel = GetLevel(CardRecv);

        //RecvFrom()
        CloseSocket();
        return iLevel;
    }
    else
    {
        CString strErr = _T("socket启动失败");
        return -1;
    }

}
Ejemplo n.º 11
0
int MySocket::SendTo(void *buf, int bytes, int flags)
// Send a block of data to a datagram socket and do not return
// until all the bytes have been written. Returns the total number
// of bytes sent or -1 if an error occurs.
{
  return SendTo(Mysocket, &sin, buf, bytes, flags);
}
Ejemplo n.º 12
0
/**
*      Send the TEXT data to remote host
*
*/
void DSocket::SendTextData(unsigned char *data,short length)
{
unsigned char *packet=new unsigned char[length+500];
int n;	

	// Text message
	packet[0]=TYPE_TEXT;
	
	// Length of hostname
	n=strlen(localname);
	packet[1]=n;
	
	// Hostname
	memcpy(&packet[2],localname,n);

	// Data length
	packet[n+2]=(unsigned char) length;
	packet[n+3]=(unsigned char) (length>>8);

	// Data
	memcpy(&packet[n+4],data,length);

	
	SendTo(packet,n+4+length,PORT_TEXT,remoteaddress);
	
}
void CMainCrossSocket::OnReceive(int nErrorCode)
{
	// TODO: 在此添加专用代码和/或调用基类
	
	unsigned char  pBuf[256];
	WORD   wPort;
	DWORD  dwIP;
	sockaddr_in MainCrsAddr;
	MainCrsAddr.sin_family = AF_INET;
		
	if(Receive(pBuf,256)>0)
	{
		wPort = MAKEWORD(pBuf[24],pBuf[25]);
		memcpy_s(&dwIP,4,pBuf+20,4);
		// if(dwIP ==0 || dwIP ==)
		if(m_pDlg)
		{
			MainCrsAddr.sin_port = htons(wPort);
			MainCrsAddr.sin_addr.s_addr = dwIP;
			SendTo(pBuf,256,(sockaddr*)&MainCrsAddr,sizeof(sockaddr_in));
			
			m_pDlg->SaveMatrixData(pBuf,256);
			m_pDlg->m_strMainIP.Format(_T("%d.%d.%d.%d"),MainCrsAddr.sin_addr.S_un.S_un_b.s_b1,MainCrsAddr.sin_addr.S_un.S_un_b.s_b2,
				MainCrsAddr.sin_addr.S_un.S_un_b.s_b3,MainCrsAddr.sin_addr.S_un.S_un_b.s_b4);
			m_pDlg->m_dwFrmCount++;
			m_pDlg->UpdateData(FALSE);
		}
	}
	CSocket::OnReceive(nErrorCode);
}
void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen)
{
	int n;
	const int on=1;
	char sendline[MAXLINE],recvline[MAXLINE+1];
	socklen_t len;
	struct sockaddr *preply_addr;
	preply_addr=malloc(servlen);
	SetSockopt(sockopt, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
	Signal(SIGALRM, recvfrom_alarm);
	while(Fgets(sendline,MAXLINE,fp) != NULL)
	{
		SendTo(sockfd,sendline,strlen(sendline),0,pservaddr,servlen);
		alarm(5);
		for(; ;)
		{
			len=servlen;
			n=recvfrom(sockfd,recvline,MAXLINE,0,preply_addr,&len);
			if(n < 0)
			{
				if(errno==EINTR)
					break;
				else
					err_sys("error");
			}
			else
			{
				recvline[n]=0; /*null terminate*/
				printf("from %s: %s", Sock_ntop_host(preply_addr, len), recvline);
			}
		}
	}
	free(preply_addr);
}
Ejemplo n.º 15
0
ssize_t MockUDPSocket::SendTo(IOVecInterface *data,
                              const ola::network::IPV4Address &ip_address,
                              unsigned short port) const {
    // This incurs a copy but it's only testing code.

    int io_len;
    const struct IOVec *iov = data->AsIOVec(&io_len);
    if (iov == NULL)
        return 0;

    unsigned int data_size = 0;
    for (int i = 0; i < io_len; i++) {
        data_size += iov[i].iov_len;
    }

    uint8_t *raw_data = new uint8_t[data_size];
    unsigned int offset = 0;
    for (int i = 0; i < io_len; i++) {
        memcpy(raw_data + offset, iov[i].iov_base, iov[i].iov_len);
        offset += iov[i].iov_len;
    }

    data->Pop(data_size);
    data->FreeIOVec(iov);
    ssize_t data_sent = SendTo(raw_data, data_size, ip_address, port);
    delete[] raw_data;
    return data_sent;
}
Ejemplo n.º 16
0
//
// 匹配
//
void CGateServer::OnMatch(CIOContext *pContext, WORD size)
{
	ProtoGateClient::Match requestMatch;
	ProtoGateServer::Match responseMatch;

	BYTE buffer[PACK_BUFFER_SIZE];
	CCacheBuffer writeBuffer(sizeof(buffer), buffer);

	//
	// 1. 解析消息
	//
	if (Parser(&pContext->GetRecvBuffer(), &requestMatch, size) == FALSE) {
		return;
	}

	//
	// 2. 检查
	//
	ProtoGateServer::ERROR_CODE err = ProtoGateServer::ERROR_CODE::ERR_NONE;

	if (pContext->guid == 0xffffffff) {
		err = ProtoGateServer::ERROR_CODE::ERR_PLAYER_NOT_LOGIN; goto ERR;
	}

	if (requestMatch.evaluation() < m_minEvaluation || requestMatch.evaluation() > m_maxEvaluation) {
		err = ProtoGateServer::ERROR_CODE::ERR_MATCH_INVALID_EVALUATION; goto ERR;
	}

	goto NEXT;
ERR:
	responseMatch.set_err(err);

	//
	// 3. 序列化消息
	//
	Serializer(&writeBuffer, &responseMatch, ProtoGateServer::RESPONSE_MSG::MATCH);

	//
	// 4. 发送
	//
	SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize());

	return;
NEXT:

	//
	// 5. 添加到待匹配玩家集合
	//
	if (pContext->dwUserData == 0xffffffff) {
		std::map<DWORD, PlayerStatus>::const_iterator itPlayer = m_evaluations[requestMatch.evaluation()].find(pContext->guid);
		if (itPlayer != m_evaluations[requestMatch.evaluation()].end()) return;

		m_evaluations[requestMatch.evaluation()][pContext->guid].pContext = pContext;
		m_evaluations[requestMatch.evaluation()][pContext->guid].timeout = 0.0f;
		m_evaluations[requestMatch.evaluation()][pContext->guid].minEvaluation = requestMatch.evaluation();
		m_evaluations[requestMatch.evaluation()][pContext->guid].maxEvaluation = requestMatch.evaluation();

		pContext->dwUserData = requestMatch.evaluation();
	}
}
Ejemplo n.º 17
0
void CGnuLocal::SendPing()
{
	m_LanNodeIDMap.clear();

	CString NetworkPing;
	NetworkPing  = m_pComm->m_NetworkName;
	NetworkPing += " PING\r\n";
	NetworkPing += "Port: " + NumtoStr(m_pNet->m_CurrentPort) + "\r\n";


	if(m_pPrefs->m_LanMode && m_pPrefs->m_LanName != "")
	{
		NetworkPing += "LAN: " + m_pPrefs->m_LanName + "\r\n";

		CString RandCache = m_pComm->m_pCache->GetRandWebCache(true);
		
		if(!RandCache.IsEmpty())
			NetworkPing += "WebCache: " + RandCache + "\r\n";
	}



	NetworkPing += "\r\n";

	// Send initial ping out to LAN network
	SendTo(NetworkPing, NetworkPing.GetLength(), UDP_PORT, NULL);

	m_pCore->LogError("UDP: Ping Sent");
}
Ejemplo n.º 18
0
int GlobalChannel::Notify(const std::string& msg, int32_t encode_type) {
    int num = 0;

    // 抽象连接对象,直接向其他连接发送消息即可
    ChannelConfAdapter* conf = ChannelConfAdapter::Instance();
    if (!conf) {
        PLOG_ERROR("channel conf adapter is null.");
        return num;
    }

    std::map<std::string, std::string>* sub_instances = NULL;
    int ret = conf->GetSubInstances(m_name, &sub_instances);
    if (ret != 0) {
        PLOG_ERROR("get sub instance from zk failed(%d).", ret);
        return num;
    }

    for (std::map<std::string, std::string>::iterator it = sub_instances->begin();
        it != sub_instances->end(); ++it) {
        if (m_appid == it->first) {
            // 不发给自己
            continue;
        }
        if ((it->second).empty()) {
            continue;
        }
        SendTo(it->first, it->second, msg, m_name, encode_type);
        ++num;
    }

    return num;
}
Ejemplo n.º 19
0
int CAsynSocket::SendTo(const void* lpBuf, int nBufLen, UINT nHostPort, LPCTSTR lpszHostAddress, int nFlags)
{
	//USES_CONVERSION;

	SOCKADDR_IN sockAddr;
	memset(&sockAddr,0,sizeof(sockAddr));

	//LPSTR lpszAscii = T2A((LPTSTR)lpszHostAddress);
	LPSTR lpszAscii = (LPTSTR)lpszHostAddress;
	sockAddr.sin_family = AF_INET;

	if (lpszAscii == NULL)
		sockAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
	else
	{
		sockAddr.sin_addr.s_addr = inet_addr(lpszAscii);
		if (sockAddr.sin_addr.s_addr == INADDR_NONE)
		{
			LPHOSTENT lphost;
			lphost = gethostbyname(lpszAscii);
			if (lphost != NULL)
				sockAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
			else
			{
				WSASetLastError(WSAEINVAL);
				return SOCKET_ERROR;
			}
		}
	}

	sockAddr.sin_port = htons((u_short)nHostPort);

	return SendTo(lpBuf, nBufLen, (SOCKADDR*)&sockAddr, sizeof(sockAddr), nFlags);
}
Ejemplo n.º 20
0
long SDMmessage::SendDM()
{
#ifdef BUILD_FOR_PNPSAT
    struct hostent *he;
    unsigned long addr;

    while ((he=gethostbyname("datamanager.spacewire")) == NULL)
    {
        sleep(1);
    }
    memcpy(&addr, he->h_addr, sizeof(addr));

    DataManager.setAddress(addr);
    DataManager.setPort(PORT_DM);
#endif
#ifdef PNP_FAKE
//    struct hostent *he;
//    unsigned long addr;
//
//    while ((he=gethostbyname("datamanager")) == NULL)
//    {
//        sleep(1);
//    }
//    memcpy(&addr, he->h_addr, sizeof(addr));
//
//    DataManager.setAddress(addr);
//    DataManager.setPort(PORT_DM);
#endif
    return SendTo(DataManager);
}
Ejemplo n.º 21
0
BOOL MySocketUDP::Broadcast(CHAR * pData, UINT nLen, USHORT uPort)
{
	SOCKADDR_IN addrin = {0};
	addrin.sin_family = AF_INET;
	addrin.sin_port = htons(uPort);
	addrin.sin_addr.S_un.S_addr = ::htonl( INADDR_BROADCAST );

	//设置广播模式
	BOOL bBroadcast = TRUE;
	int iRet = ::setsockopt( m_uSocket, SOL_SOCKET, SO_BROADCAST,
		(char *)&bBroadcast,sizeof( bBroadcast ) );
	if(SOCKET_ERROR == iRet)
	{
		return FALSE;
	}

	BOOL bRet = SendTo(pData, nLen, &addrin);

	//设置非广播模式
	bBroadcast = FALSE;
	iRet = ::setsockopt( m_uSocket, SOL_SOCKET, SO_BROADCAST,
		(char *)&bBroadcast,sizeof( bBroadcast ) );
	if(SOCKET_ERROR == iRet)
	{
		//Create();
	}

	return bRet;
}
Ejemplo n.º 22
0
//
// 心跳
//
void CGateServer::OnHeart(CIOContext *pContext, WORD size)
{
	ProtoGateClient::Heart requestHeart;
	ProtoGateServer::Heart responseHeart;

	BYTE buffer[PACK_BUFFER_SIZE];
	CCacheBuffer writeBuffer(sizeof(buffer), buffer);

	//
	// 1. 解析消息
	//
	if (Parser(&pContext->GetRecvBuffer(), &requestHeart, size) == FALSE) {
		return;
	}

	//
	// 2. 心跳
	//
	responseHeart.set_timestamp(requestHeart.timestamp());

	//
	// 3. 序列化消息
	//
	Serializer(&writeBuffer, &responseHeart, ProtoGateServer::RESPONSE_MSG::HEART);

	//
	// 4. 发送
	//
	SendTo(pContext, buffer, writeBuffer.GetActiveBufferSize());
}
Ejemplo n.º 23
0
bool CUDPSocket :: SendTo( string address, uint16_t port, BYTEARRAY message )
{
	if( m_Socket == INVALID_SOCKET || m_HasError )
		return false;

	// get IP address

	struct hostent *HostInfo;
	uint32_t HostAddress;
	HostInfo = gethostbyname( address.c_str( ) );

	if( !HostInfo )
	{
		m_HasError = true;
		// m_Error = h_error;
		CONSOLE_Print( "[UDPSOCKET] error (gethostbyname)" );
		return false;
	}

	memcpy( &HostAddress, HostInfo->h_addr, HostInfo->h_length );
	struct sockaddr_in sin;
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = HostAddress;
	sin.sin_port = htons( port );

	return SendTo( sin, message );
}
Ejemplo n.º 24
0
long SDMDeletesub::Send()
{
	int result;
	result = SendTo(source);
	if (result <= 0)
		return SDM_MESSAGE_SEND_ERROR;
	return result;
}
Ejemplo n.º 25
0
/**
*      Send the VIDEO data to remote host
*
*/
void DSocket::SendVideoData(unsigned char *data,int length)
{

// Better to attach video header....
// If dynamic format is supported...
SendTo(data,length,PORT_VIDEO,remoteaddress);
	
}
Ejemplo n.º 26
0
long SDMSerreqst::Send(const SDMComponent_ID& destination)
{
	int result;
	result = SendTo(destination);
	if (result <= 0)
		return SDM_MESSAGE_SEND_ERROR;
	return result;
}
Ejemplo n.º 27
0
// ADC数据采集停止
//************************************
// Method:    OnADCSampleStop
// FullName:  CADCSet::OnADCSampleStop
// Access:    public 
// Returns:   void
// Qualifier:
// Parameter: void
//************************************
void CADCSet::OnADCSampleStop(void)
{
	int iPos = 0;
	iPos = ADCSetFrameHead(BroadCastPort, SendSetCmd, ADSetReturnPort);

	OnStopSample(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
 
	Sleep(ADCOperationSleepTime);
 
	OnStopSample(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);

	Sleep(ADCOperationSleepTime);

	OnStopSample(iPos);
	SendTo(m_ucFrameData, SndFrameSize, m_uiSendPort, IPBroadcastAddr);
}
Ejemplo n.º 28
0
	int Broadcast( int sd,char* message, int buffSize, SockAddr &addr )
	{
		int broadcast = 1;    
		setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char*)&broadcast, sizeof(int));
		int bytes_sent = SendTo(sd,message,buffSize,addr);
		broadcast = 0;
		setsockopt(sd, SOL_SOCKET, SO_BROADCAST, (char*)&broadcast, sizeof(int));
		return bytes_sent;
	}
Ejemplo n.º 29
0
int SocketLayer::SendToTTL( SOCKET s, const char *data, int length, const char ip[ 16 ], unsigned short port, int ttl )
{
	unsigned int binaryAddress;
	binaryAddress = inet_addr( ip );
	SystemAddress sa(binaryAddress,port);

	if (slo)
		return slo->RakNetSendTo(s,data,length,sa);

#if !defined(_XBOX) && !defined(X360)
	int oldTTL;
	socklen_t opLen=sizeof(oldTTL);
	// Get the current TTL
	if (getsockopt(s, IPPROTO_IP, IP_TTL, ( char * ) & oldTTL, &opLen ) == -1)
	{
#if defined(_WIN32) && defined(_DEBUG)
		DWORD dwIOError = GetLastError();
		LPVOID messageBuffer;
		FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL, dwIOError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),  // Default language
			( LPTSTR ) & messageBuffer, 0, NULL );
		// something has gone wrong here...
		RAKNET_DEBUG_PRINTF( "getsockopt(IPPROTO_IP,IP_TTL) failed:Error code - %d\n%s", dwIOError, messageBuffer );
		//Free the buffer.
		LocalFree( messageBuffer );
#endif
	}

	// Set to TTL
	int newTTL=ttl;
	if (setsockopt(s, IPPROTO_IP, IP_TTL, ( char * ) & newTTL, sizeof ( newTTL ) ) == -1)
	{

#if defined(_WIN32) && defined(_DEBUG)
		DWORD dwIOError = GetLastError();
		LPVOID messageBuffer;
		FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL, dwIOError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),  // Default language
			( LPTSTR ) & messageBuffer, 0, NULL );
		// something has gone wrong here...
		RAKNET_DEBUG_PRINTF( "setsockopt(IPPROTO_IP,IP_TTL) failed:Error code - %d\n%s", dwIOError, messageBuffer );
		//Free the buffer.
		LocalFree( messageBuffer );
#endif
	}

	// Send
	int res = SendTo(s,data,length,ip,port,false);

	// Restore the old TTL
	setsockopt(s, IPPROTO_IP, IP_TTL, ( char * ) & oldTTL, opLen );

	return res;
#else
	return 0;
#endif
}
Ejemplo n.º 30
0
void Zoo::FinishTrain() {
  for (auto i = 0; i < num_servers_; i++) {
    int dst_rank = server_id_to_rank(i);
    MessagePtr msg(new Message());
    msg->set_src(rank());
    msg->set_dst(dst_rank);
    msg->set_type(MsgType::Server_Finish_Train);
    SendTo(actor::kCommunicator, msg);
  }
}