miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

upnpDiscover(), Socket Error

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation
View previous topic :: View next topic  
Author Message
PortmappingGuru



Joined: 06 Feb 2011
Posts: 8

PostPosted: Sun Feb 06, 2011 12:30 pm    Post subject: upnpDiscover(), Socket Error Reply with quote

Hi!

I'm trying to make a small console based application, that automatically opens a port on my router. First I try to find the router through upnpDiscover, but all I get is a Socket Error. I guess it has something to do with the minissdpdsock. I'm using Visual Studio 2010 and am developing for Win32 (my OS: Win7).

Code:

#include <stdio.h>
#include <conio.h>
#include <winsock2.h>

#define STATICLIB

#include "Dependency\miniupnpc.h"
#include "Dependency\miniwget.h"
#include "Dependency\upnpcommands.h"
#include "Dependency\upnperrors.h"

struct UPNPDev *devices;

void main()
{
   printf("This is a UPnP test!\n\n");
   
   printf("Searching for UPnP devices!\n");
   
   devices = upnpDiscover(30, NULL, NULL, 0);
   if(devices != NULL)
   {
      printf("UPnP devices were found!\n");

      freeUPNPDevlist(devices);
   }

   _getch();
}


This is the Output:
---------------------

This is a UPnP test!

Searching for UPnP devices!
Socket error: socket, 10093

---------------------

What am I doing wrong?

Thanks for your help!
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Mon Feb 07, 2011 12:15 am    Post subject: Reply with quote

You havent made the initialisation of Winsock.
Code:

   WSADATA wsaData;
   int nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
   if(nResult != NO_ERROR)
   {
      fprintf(stderr, "WSAStartup() failed.\n");
      return -1;
   }

_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
PortmappingGuru



Joined: 06 Feb 2011
Posts: 8

PostPosted: Mon Feb 07, 2011 10:25 am    Post subject: Reply with quote

Ah ok. I thought this is done by miniupnpc automatically.

Thanks a lot for your help! Now it's working Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.