Results 1 to 19 of 19

Thread: Help me plz. Socket.

  1. #1
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default Help me plz. Socket.

    Hi all. Srry my english =(

    i have a problem with sockets.

    Code:

    PHP Code:
    #include <ClanLib\core.h>
    #include <ClanLib\application.h>
    #include <ClanLib\network.h>

    class app
    {
    public:
        static 
    int main(const std::vector<CL_String> &args)
        {
            
    CL_SetupCore score;
            
    CL_SetupNetwork snet;

            
    CL_ConsoleWindow console("Error Log");

            try
            {
                
    CL_SocketName lport("6767");
                
    CL_TCPListen l(lport);
            }
            catch(
    CL_Exception e)
            {
                
    CL_Console::write_line(e.message);
                
    CL_Console::wait_for_key();
            }

            return 
    0;
        }
    };

    CL_ClanApplication App(&app::main); 
    Console, "Unable to create socket handle".

    All examples with this error. I tried:

    PHP Code:
    #pragma comment(lib, "ws2_32.lib")
    #include <winsock2.h>
    #include <windows.h>
    #include <ClanLib\core.h>
    #include <ClanLib\application.h>
    #include <ClanLib\network.h> 
    result: Unable to create socket handle

    PHP Code:
    #include <winsock2.h>
    #include <windows.h>
    #include <ClanLib\core.h>
    #include <ClanLib\application.h>
    #include <ClanLib\network.h> 
    result: Unable to create socket handle

    .............

    and more...

    tried everything connected with the connecting / disconnecting the library ...error. Help me plz

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Maybe its a permission problem - did you try running it as an administrator?

  3. #3
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by sphair View Post
    Maybe its a permission problem - did you try running it as an administrator?
    I ran as administrator, turned off the firewall and antivirus ... error

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    What operating system and what version are you running?

    Does CL_TCPConnection work or does that one also fail?

  5. #5
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by Magnus Norddahl View Post
    What operating system and what version are you running?

    Does CL_TCPConnection work or does that one also fail?
    CL_TCPConnection not working. Same error.

    I use WindowsXP SP3, ClanLib 2.1.1 and MVSC++ 9.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Does, ClanLib-2.1.1/Tests/Network/TCPConnection work?

  7. #7
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by rombust View Post
    Does, ClanLib-2.1.1/Tests/Network/TCPConnection work?
    No. Does not work.

    Console, "Unable to create socket handle".

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Humm, I get

    Code:
    --- Begin of test1 ---
    
    Time start: 322682
    Resource temporarily unavailable
    When I run it through the debugger, it works....

  9. #9
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    There was problem with the test. The following patch fixes it:
    Code:
    Index: test.cpp
    ===================================================================
    --- test.cpp	(revision 4458)
    +++ test.cpp	(working copy)
    @@ -109,6 +109,11 @@
     	while (out_line.length() < 1024)
     	{
     		char buffer[1024];
    +
    +		int wakeup_reason = connection.get_read_event().wait(15000);
    +		if (wakeup_reason == -1)
    +			throw CL_Exception(cl_text("read_line timed out"));
    +
     		int bytes_read = connection.peek(buffer, 1024);
     		if (bytes_read <= 0)
     			break;
    The test works on my PC

  10. #10
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Still CL_Exception shows "Unable to create socket handle".
    I may be doing something wrong? All functions are in working order, except for functions socket.

    "There was problem with the test."

    But what about the code that I pointed out in a post #1?

  11. #11
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I have no idea

    May a virus killer / firewall on your PC is automatically blocking new applications that attempt to connect to the internet

    Try the example code at:

    http://msdn.microsoft.com/en-us/libr...25(VS.85).aspx

  12. #12
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by rombust View Post
    I have no idea

    May a virus killer / firewall on your PC is automatically blocking new applications that attempt to connect to the internet
    I just thought. Check for another programming language. Applications associated with the network working. Please write the sample code (easy), so I could check and what the settings in the project should I do? Please

  13. #13
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    ???

    This does contain the sample code, and you cannot get easier than that

    http://msdn.microsoft.com/en-us/libr...25(VS.85).aspx

    You may want to try changing "127.0.0.1" to "88.198.16.169" (clanlib.org)

  14. #14
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    However your code "should" work.

    Inside CL_Win32Socket::create_socket_handle(int type) (in Sources/Network/Socket/win32_socket.cpp)

    It is doing:

    Code:
    (type = SOCK_STREAM)
    handle = socket(AF_INET, type, 0);
    if (handle == INVALID_SOCKET)
    	throw CL_Exception(L"Unable to create socket handle");
    You could try:
    int handle = socket(AF_INET, type, IPPROTO_TCP); instead

    (You can test this directly in your code instead of using CL_TCPListen )

  15. #15
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    PHP Code:
    #include <ClanLib\core.h>
    #include <ClanLib\application.h>
    #include <ClanLib\network.h>

    class app
    {
    public:
        static 
    int main(const std::vector<CL_String> &args)
        {
            
    CL_SetupCore score;
            
    CL_SetupNetwork snet;

            
    CL_ConsoleWindow console("Error Log");

            try
            {
                
    CL_SocketName lport("6767");
                
    int handle socket(AF_INETSOCK_STREAMIPPROTO_TCP);
                if (
    handle == INVALID_SOCKET)
                {
                    
    MessageBox(0"Unable to create socket handle""Error"MB_OK);
                }
            }
            catch(
    CL_Exception e)
            {
                
    CL_Console::write_line(e.message);
                
    CL_Console::wait_for_key();
            }

            return 
    0;
        }
    };

    CL_ClanApplication App(&app::main); 
    Message, "Unable to create socket handle"

  16. #16
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    When the socket command fails, what error does WSAGetLastError() return?

    i.e.
    Code:
                    int handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 
                    if (handle == INVALID_SOCKET) 
                    { 
                        int error_value = WSAGetLastError() ;
                        ...

  17. #17
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by rombust View Post
    When the socket command fails, what error does WSAGetLastError() return?

    i.e.
    Code:
                    int handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 
                    if (handle == INVALID_SOCKET) 
                    { 
                        int error_value = WSAGetLastError() ;
                        ...
    WSAGetLastError() return 10106

  18. #18
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by Aikidos View Post
    WSAGetLastError() return 10106
    That is: WSAEPROVIDERFAILEDINIT

    "Service provider failed to initialize.
    The requested service provider could not be loaded or initialized. This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed."

    This problem is not clanlib, but something deeper. Google did not seem to help, except other people get the error, but nobody knows of a solution - Except:

    "Some component of winsock wants SystemRoot to be present in environment" - whatever that means :~)

  19. #19
    Lesser Knight
    Join Date
    May 2010
    Posts
    32

    Default

    Quote Originally Posted by rombust View Post
    That is: WSAEPROVIDERFAILEDINIT

    "Service provider failed to initialize.
    The requested service provider could not be loaded or initialized. This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed."

    This problem is not clanlib, but something deeper. Google did not seem to help, except other people get the error, but nobody knows of a solution - Except:

    "Some component of winsock wants SystemRoot to be present in environment" - whatever that means :~)
    Problem solved. Introduced the command line:

    PHP Code:
    netsh winsock reset 
    thnx all

Similar Threads

  1. Socket Assert
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-20-2007, 05:31 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •