Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
承插C++;到PHP或Android_Php_Android_C++_Sockets - Fatal编程技术网

承插C++;到PHP或Android

承插C++;到PHP或Android,php,android,c++,sockets,Php,Android,C++,Sockets,我有客户机-服务器的代码。服务器代码使用C++与本地端口和客户端,我想使用PHP或Android。但是我不知道如何编写代码 注意: 服务器应用程序使用本地端口10001 我的代码服务器(networkex.cpp) 我的主线程(mainthread.cpp) boolcmainthread::CommandProcess(char*pszCmd) { int nWordNum=::parsingcomd(pszCmd,max_cheat_word,s_pszDstCheat,max_cheat_

我有客户机-服务器的代码。服务器代码使用C++与本地端口和客户端,我想使用PHP或Android。但是我不知道如何编写代码

注意:

  • 服务器应用程序使用本地端口10001
  • 我的代码服务器(networkex.cpp)

    我的主线程(mainthread.cpp)

    boolcmainthread::CommandProcess(char*pszCmd)
    {
    int nWordNum=::parsingcomd(pszCmd,max_cheat_word,s_pszDstCheat,max_cheat_word_size);
    如果(nWordNum MAX_PATCHER_PER_GLOBAL)
    dwBufNum=每个全局的最大修补程序;
    ::StringOutput(“修补程序服务器增加(%d->%d)”,m_dwPatchServerNum,dwBufNum);
    m_dwPatchServerNum=dwBufNum;
    返回true;
    }
    否则,如果(!strcmp(“/patchdown”,s_pszdstcheak[0]))
    {
    德沃德·德布夫努姆;
    if(m_dwPatchServerNum 1)
    {
    如果(!strcmp(“外部块”,s_pszdstcheak[1])&&nWordNum==7)
    {
    if(_SetReserveExternalClose(atoi(s_pszdstcheal[2])、atoi(s_pszdstcheal[3])、atoi(s_pszdstcheal[4])、atoi(s_pszdstcheal[5])、atoi s_pszdstcheal[6]))
    ::StringOutput(“接受保留”);
    其他的
    ::StringOutput(“预订时间错误”);
    返回true;
    }
    }
    }
    否则如果(!strcmp(“/loginstat”,s_pszdstcheak[0]))
    {
    如果(m_bExternalOpen)
    ::StringOutput(“外部访问状态”);
    其他的
    ::StringOutput(“外部连接错误状态”);
    返回true;
    }
    否则如果(!strcmp(“/clientcount”,s_pszdstcook[0]))
    {
    DWORD dwClientCount=CountAliveConnection();
    ::StringOutput(“连接:%d”,dwClientCount);
    返回true;
    }
    返回false;
    }
    
    我希望我的客户端只发送像“/打开”或“关闭”这样的消息,但我不知道用php或android编写代码的方法。有人能帮我解决问题吗

    编辑

    我已经尝试使用这个php代码了

    <?php
    $host    = "127.0.0.1";
    $port    = 10001;
    $message = "open";
    echo "Message To server :".$message;
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
    // connect to server
    $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");  
    // send string to server
    socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
    // get server response
    $result = socket_read ($socket, 1024) or die("Could not read server response\n");
    echo "Reply From Server  :".$result;
    // close socket
    socket_close($socket);
    ?> 
    
    
    

    我的浏览器和我的服务器应用程序中的响应没有收到消息/open

    你最好谷歌android客户端服务器示例。你很快就会找到现成的java代码。如果我可以使用php,我想你也可以找到现成的php服务器代码。但是你有这样的域名吗?域名?为什么?我只是在本地试试,先生。。。使用ip 127.0.0.1或localhostOk。在本地pc上。您知道如何在那里安装php服务器代码吗?如果您的客户端运行在android设备上,则无法使用127.0.0.1或localhost进行连接。
    bool CMainThread::CommandProcess(char* pszCmd)
    {
    int nWordNum = ::ParsingCommand(pszCmd, max_cheat_word, s_pszDstCheat, max_cheat_word_size);
    if(nWordNum <= 0)
        return false;
    
    if(!strcmp("/open", s_pszDstCheat[0]))
    {
        ::StringOutput("Connection External Open"); 
        m_bExternalOpen = true;
        return true;
    }
    else if(!strcmp("/close", s_pszDstCheat[0]))
    {
        ::StringOutput("Connection External Close");    
        m_bExternalOpen = false;
        return true;
    }
    else if(!strcmp("/patchup", s_pszDstCheat[0]))
    {
        DWORD dwBufNum = m_dwPatchServerNum + 1;
        if(dwBufNum > MAX_PATCHER_PER_GLOBAL)
            dwBufNum = MAX_PATCHER_PER_GLOBAL;      
    
        ::StringOutput("Patch Server increases(%d -> %d)", m_dwPatchServerNum, dwBufNum);   
        m_dwPatchServerNum = dwBufNum;
        return true;
    }
    else if(!strcmp("/patchdown", s_pszDstCheat[0]))
    {
        DWORD dwBufNum;
        if(m_dwPatchServerNum <= 1)
            dwBufNum = 1;
        else
            dwBufNum = m_dwPatchServerNum - 1;  
    
        ::StringOutput("Patch Server decreases(%d -> %d)", m_dwPatchServerNum, dwBufNum);   
        m_dwPatchServerNum = dwBufNum;
        return true;
    }
    else if(!strcmp("/예약", s_pszDstCheat[0]))
    {
        if(nWordNum > 1)
        {
            if(!strcmp("The outer block", s_pszDstCheat[1]) && nWordNum == 7)
            {
                if(_SetReserveExternalClose(atoi(s_pszDstCheat[2]), atoi(s_pszDstCheat[3]), atoi(s_pszDstCheat[4]), atoi(s_pszDstCheat[5]), atoi(s_pszDstCheat[6])))
                    ::StringOutput("Reservations accepted");
                else
                    ::StringOutput("Booking time errors");
                return true;
            }
        }
    }
    else if(!strcmp("/loginstat", s_pszDstCheat[0]))
    {
        if ( m_bExternalOpen )
            ::StringOutput("External access status");
        else
            ::StringOutput("External connection error status");
        return true;
    }
    else if(!strcmp("/clientcount", s_pszDstCheat[0]))
    {
        DWORD dwClientCount = CountAliveConnection();
        ::StringOutput( "Connection : %d", dwClientCount );
        return true;
    }
    
    return false;
    }
    
    <?php
    $host    = "127.0.0.1";
    $port    = 10001;
    $message = "open";
    echo "Message To server :".$message;
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
    // connect to server
    $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");  
    // send string to server
    socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
    // get server response
    $result = socket_read ($socket, 1024) or die("Could not read server response\n");
    echo "Reply From Server  :".$result;
    // close socket
    socket_close($socket);
    ?>