Я бы хотел подключиться к своему серверу c ++, используя php ...
Пока что я получил:
server.cpp
#include <winsock2.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
WSADATA wsaData;
SOCKET mySocket;
SOCKET myBackup;
SOCKET acceptSocket;
sockaddr_in myAddress;
// setup WSA and socket....
if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR )
{
cerr<<"Socket Initialization: Error with WSAStartup\n";
system("pause");
WSACleanup();
exit(10);
}
//Create a socket
mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( mySocket == INVALID_SOCKET )
{
cerr<<"Socket Initialization: Error creating socket"<<endl;
system("pause");
WSACleanup();
exit(11);
}
myBackup = mySocket;
//bind
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" );
myAddress.sin_port = htons( 25555 );
if ( bind ( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress) ) == SOCKET_ERROR )
{
cerr<<"ServerSocket: Failed to connect\n";
system("pause");
WSACleanup();
exit(14);
}
//listen
if ( listen ( mySocket, 10 ) == SOCKET_ERROR )
{
cout<<"ERR: ServerSocket: Error listening on socket\n";
system("pause");
WSACleanup();
exit(15);
}
cout<<"srv started. listeninig...\n";
//accept
acceptSocket = accept( myBackup, NULL, NULL );
while ( acceptSocket == SOCKET_ERROR )
{
acceptSocket = accept( myBackup, NULL, NULL );
}
mySocket = acceptSocket;
cout<<"done.\n";
return 0;
}
и клиент php
<?php
$port = 25555;
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
#socket_bind($socket,'',$port);
socket_connect($socket, '/my_ip/', $port);
echo 'connecting...';
?>
Я не знаю, что делать. сервер c ++ просто не видит клиента php ...