#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    44
    Rep Power
    12

    winsock server only works locally


    hello new to winsocl thought i would make a server it works fine localy but not remotly
    Heres the main code:

    PHP Code:
    int _tmain(int argcTCHARargv[], TCHARenvp[])
    {

        
    int nRetCode 0;    

        
    cout << "Press ESCAPE to terminate program\r\n";
        
    AfxBeginThread(MTServerThread,0);
        while(
    _getch()!=27);

        
    closesocket(server);
        
    WSACleanup();

        return 
    nRetCode;
    }
    UINT  MTServerThread(LPVOID pParam)
    {        
        
    WSADATA wsaData;
        
    sockaddr_in local;
        
    int wsaret=WSAStartup(0x101,&wsaData);

        if(
    wsaret!=0)
        {
            return 
    0;
        }

        
    local.sin_family=AF_INET;
        
    local.sin_port=htons(179);
        
    local.sin_addr.s_addr=INADDR_ANY;

        
    server=socket(AF_INET,SOCK_STREAM,0);
        if(
    server==INVALID_SOCKET)
        {
            return 
    0;
        }
        if(
    bind(server,(sockaddr*)&local,sizeof(local))!=0)
        {
            return 
    0;
        }
        if(
    listen(server,10)!=0)
        {
            return 
    0;
        }

        
    SOCKET client;
        
    sockaddr_in from;
        
    int fromlen=sizeof(from);

        while(
    true)
        {
            
    client=accept(server,
                (
    struct sockaddr*)&from,&fromlen);
            
    conntemp=client;
            
    AfxBeginThread(ClientThread,(LPVOID)client);    
        }    

        return 
    0;
    }

    UINT  ClientThread(LPVOID pParam)
    {
        
    char buff[512];
        
    CString cmd;
        
    CString params;
        
    int n;
        
    int x;
        
    BOOL auth=false;
        
    SOCKET client=(SOCKET)pParam;
        
    strcpy(buff,"Server Ready.\r\n");
        
    send(client,buff,strlen(buff),0);
        
        while(
    true)
        {
            
    strcpy(buff,"Password:\r\n");
            
    send(client,buff,strlen(buff),0);
            
    n=recv(client,buff,512,0);
            if(
    n==SOCKET_ERROR )            
                break;
            
    buff[n]=0;
            
    ParseCmd(buff,cmd,params);
            if (
    cmd=="PASS"){
                
    strcpy(buff,"Authorized.\r\n");
                
    send(client,buff,strlen(buff),0);
                
    auth=true;
                break;
            }
            
    strcpy(buff,"Invalid password.\r\n");
            
    send(client,buff,strlen(buff),0);
            
        }
        while(
    true)
        {
            
    n=recv(client,buff,512,0);
            if(
    n==SOCKET_ERROR )            
                break;
            
    buff[n]=0;
            if(
    ParseCmd(buff,cmd,params))
            {
        
    //blah
            
    }


        }        
        
    strcpy(buff,"Closing Connection.\r\n");
        
    send(client,buff,strlen(buff),0);
        
    closesocket(client);
        return 
    0;

  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    What failure indications do you get? Could the fault be in your client? Did you also write the client? Are you implementing the Border Gateway Protocol correctly?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    44
    Rep Power
    12
    Well I have written a client but to test this i am using telnet, so I knew for sure it would be in the server function(s)
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Would you mind posting the full source so that I can test it and see what's happening? A zipfile or tarball would work fine. Also, what are you developing it with? I'll be using Visual C++6.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    44
    Rep Power
    12
    I am also using visual c++ (console application)
    Attached Files
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Originally posted by the-griff
    I am also using visual c++ (console application)
    OK, just got it at 1815 PDT. In the middle of a busy weekend, so I might not be able to do much until Monday.
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Preliminary findings:
    Builds. Got single warning due to a lone backslash ('\') in the string on line 200 of MTServer.cpp. Corrected it by doubling the backslash.

    Connected to server on local machine (127.0.0.1 on my WinME laptop) via telnet. Get "Password:" prompt, but every single key I press causes "Invalid Password." and a new "Password:" prompt to display. What am I supposed to type to get it to accept a password?

    Wired WinME laptop to my Win2k desktop LAN. Ran server on laptop and connected to it via telnet on the Win2k box. Got same results: "Password:" prompt with "Invalid Password." and new "Password:" prompt displayed with every key I press.

    So as far as I can tell, I'm not getting the same results that you reported.

    Here's a thought. NT/2000/┐XP? are far more security-minded and less promiscuous/laissez-faire than Win95/98/ME. I have encountered problems with running a server on my Win2k and it didn't want my WinME to connect -- the WinME hadn't been authenticated, I guess. I have just found it much easier to run servers on the WinME and control all LAN operations from the Win2k box. I'm not completely sure about XP, because I have avoided it as much as possible, but since it's built on NT/2k technology, I assume that it shares much the same security features and obstacles.

    Anyway, I'll check again around 2200 PDT (it's now about 1940) and then probably won't have another chance until Sunday night.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    44
    Rep Power
    12
    On a closer look I did find that the problem was with my client. So i think this thread should be ended. Thanks all for your help!

IMN logo majestic logo threadwatch logo seochat tools logo