本文整理汇总了C++中UdpSocket::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::Bind方法的具体用法?C++ UdpSocket::Bind怎么用?C++ UdpSocket::Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpSocket
的用法示例。
在下文中一共展示了UdpSocket::Bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
UdpDriver drv;
drv.Init(1);
UdpSocketHandlerSharedPtr pHdlr(new PingPangUdpHandler());
drv.SetHandler(pHdlr);
UdpSocket svr;
if(svr.Init())
{
return -1;
}
if(svr.Bind(SockAddress(1234,"127.0.0.1")))
{
return -1;
}
drv.AddSocket(svr.GetFD());
while(1)
{
if(drv.Loop(1,10) < 0)
{
return -1;
}
}
return 0;
}
示例2: runTimeClient
void runTimeClient (void *ptr) {
int port = *ssi_pcast (int, ptr);
/*TcpSocket sock;
sock.create ();
printf ("request framework time");
ssi_size_t time;
while (!sock.connect ("localhost", port)) {
printf (".");
sleep_ms (100);
}
int n_recv = sock.recv (&time, sizeof (time));
if (n_recv > 0) {
printf ("\nreceived time in ms: %u\n", time);
}
sock.shutdown (SD_BOTH);
sock.close (); */
UdpSocket sock;
sock.Bind (IpEndpointName ("localhost", 459234));
printf ("request framework time\n");
char msg = 0;
IpEndpointName server ("localhost", port);
sock.SendTo (server, &msg, 1);
ssi_size_t time;
int recv = sock.ReceiveFrom (server, ssi_pcast (char, &time), sizeof (ssi_size_t));
if (recv != -1) {
printf ("\nreceived time in ms: %u\n", time);
}
Sleep (2000);
}
示例3: main
int main(){
if(!winSockDll.Init()){
std::cout<<"Couldn't load winsock"<<std::endl;
system("pause");
return 1;
}
connections = (Address*)calloc(64, sizeof(Address));
addr = Address("127.0.0.1", 2222);
sConnect = UdpSocket();
sConnect.Bind(addr);
std::cout << "Server started..." << std::endl;
char* buffer = new char[512];
bool clientexist = false;
while(true){
clientexist = false;
ZeroMemory(buffer, 512);
sConnect.Receive(buffer, 512, &storeAddr);
for(int i = 0; i < Counter; i++){
if(storeAddr.Equals(connections[i])){
std::cout << "Client["<<i<<"]: "<<buffer<<std::endl;
clientexist = true;
}
}
if(!clientexist){
connections[Counter] = storeAddr;
std::cout<<"New Client: "<<Counter<<std::endl;
std::cout << "Client["<<Counter<<"]: "<< buffer << std::endl;
Counter++;
}
}
winSockDll.Cleanup();
return 0;
}
示例4: _UdpSocket_Bind
value _UdpSocket_Bind(value a, value b) {
UdpSocket* s = (UdpSocket*) val_data(a);
return alloc_bool(s->Bind(val_int(b)));
}