방금 Poco 라이브러리를 사용하기 시작했습니다. Poco의 DatagramSocket 객체를 사용하여 두 대의 컴퓨터가 통신하는 데 문제가 있습니다. 특히, receiveBytes 함수는 Wireshark를 실행하고 목적지의 컴퓨터에 도착한 UDP 패킷을 보내고 있음에도 불구하고 반환하지 않는 것처럼 보입니다. 나는 내가 간단한 것을 생략하고 있다고 가정하고 이것은 내 모든 부분에서 바보 같은 실수로 인한 것이다. Visual Studio Express 2010을 사용하여 Windows 7에서 Poco 1.4.3p1을 컴파일했습니다. 다음은 Poco를 사용하는 방법을 보여주는 코드 단편입니다. 모든 조언을 주시면 감사하겠습니다.Poco C++ 1.4.3p1의 DatagramSocket ReceiveBytes()는 결코 반환하지 않습니다. 나는 그 기능을 잘못 사용하고 있는가?
(나는 문제가 있어요 곳)
#include "Poco\Net\DatagramSocket.h" #include "Poco\Net\SocketAddress.h" #include "Serializer.h" #include <iostream> int main() { Poco::Net::SocketAddress remoteAddr("192.168.1.116", 5678); //The IP address of the remote (sending) machine Poco::Net::DatagramSocket mSock; //We make our socket (its not connected currently) mSock.connect(remoteAddr); //Sends/Receives are restricted to the inputted IPAddress and port //Now lets try to get some datas std::cout << "Waiting for float" << std::endl; unsigned char float_bytes[4]; mSock.receiveBytes((void*)float_bytes, 4); //The code is stuck here waiting for a packet. It never returns... //Finally, lets convert it to a float and print to the screen float net_float; BinToFloat(float_bytes, &net_float); //Converting the binary data to a float and storing it in net_float std::cout << net_float << std::endl; system("PAUSE"); return 0; }
이 시간 내 주셔서 감사 받기
#include "Poco\Net\DatagramSocket.h"
#include "Serializer.h" //A library used for serializing data
int main()
{
Poco::Net::SocketAddress remoteAddr("192.168.1.140", 5678); //The IP address of the remote (receiving) machine
Poco::Net::DatagramSocket mSock; //We make our socket (its not connected currently)
mSock.connect(remoteAddr); //Sends/Receives are restricted to the inputted IPAddress and port
unsigned char float_bytes[4];
FloatToBin(1234.5678, float_bytes); //Serializing the float and storing it in float_bytes
mSock.sendBytes((void*)float_bytes, 4); //Bytes AWAY!
return 0;
}
보내기.
왜 지구에서 'C'에 태그를 지정 했습니까? – Puppy
그건 내 실수 였어. 당신이 맞습니다, 제 질문은 C와 아무 관련이 없습니다. 정정에 감사드립니다. – user1405648