Notifications
                
            
                Clear all
    
            
        [Closed] TCP Sockets with SDK
Nov 12, 2015 1:34 pm
                      Has anyone done any server talk from the maxsdk? I have been searching around the web but can’t find any information on using sockets from the max sdk.
I have a good working console server and client working, but as soon as I try and add…
#include <winsock2.h>
All hell breaks loose. So has anyone done any client server work with the sdk and could you point me to what I can use?
Thanks
                             2 Replies                        
                    Nov 12, 2015 1:34 pm
                      wondering if there is some way to use
MaxNetManager* manager = CreateManager();
to contact my own server?  It looks like they have removed any samples from the SDK after ver 6
Nov 12, 2015 1:34 pm
                      ah, I got it to work.
void Socket_Test::ConnectToHost(){
    WSADATA wsaData; 
    int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); 
    if ( iResult != NO_ERROR ) 
		ExecuteMAXScriptScript(_T("print \"Error at WSAStartup() 
\""), 0, 0);
    // Create a socket. 
    SOCKET Socket; 
    Socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); 
    if ( Socket == INVALID_SOCKET ) { 
		ExecuteMAXScriptScript(_T("print \"Error at socket(): %ld
\""), WSAGetLastError(), 0);
        WSACleanup(); 
        return; 
    }
    else{
        ExecuteMAXScriptScript(_T("print \"Good Socket \""), 0, 0);
    }
    sockaddr_in SockAddr;
    SockAddr.sin_family = AF_INET; 
	
    SockAddr.sin_addr.s_addr = inet_addr( "192.168.xxx.xx" );
    SockAddr.sin_port = htons( 6666 ); 
    if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr))!=0){
        ExecuteMAXScriptScript(_T("print \"Failed to establish connection with server \""), 0, 0);
	WSACleanup();
    }
    else{
        ExecuteMAXScriptScript(_T("print \"Connection with server! \""), 0, 0);
    }
    char buffer[256];
    memset(buffer,0,255);
    int inDataLength = recv(Socket,buffer,256,0);
    HWND hName = GetDlgItem(theSocket_Test.hPanel, IDC_COM_MESSAGE);
    TCHAR str[256];
    _swprintf(str, _T("%s"), buffer);
    Static_SetText(hName, str);
    shutdown(Socket, 0x01);
    closesocket(Socket);
    WSACleanup();
}