-1

I am working a project need to convert a TCP socket codes to maxscript,with my knowledge,it is hard for me to convert it,does anyone can help me to finish it,thanks in advance! Here is the code for c# works well in console mode:

Server code:

using System;
using System.Net.Sockets;
using System.Threading;
public class AsynchIOServer
{
    static TcpListener tcpListener = new TcpListener(10);
    static void Listeners()
    {
        Socket socketForClient = tcpListener.AcceptSocket();
        if (socketForClient.Connected)
        {
            Console.WriteLine("Client:" + socketForClient.RemoteEndPoint + " now connected to server.");
            NetworkStream networkStream = new NetworkStream(socketForClient);
            System.IO.StreamWriter streamWriter =
            new System.IO.StreamWriter(networkStream);
            System.IO.StreamReader streamReader =
            new System.IO.StreamReader(networkStream);

            while (true)
            {
                string theString = streamReader.ReadLine();
                Console.WriteLine("Message recieved by client:" + theString);
                if (theString == "exit")
                    break;
            }
            streamReader.Close();
            networkStream.Close();
            streamWriter.Close();
        }
        socketForClient.Close();
        Console.WriteLine("Press any key to exit from server program");
        Console.ReadKey();
    }
    public static void Main()
    {
        tcpListener.Start();
        Console.WriteLine("************This is Server program************");
        Console.WriteLine("Hoe many clients are going to connect to this server?:");
        int numberOfClientsYouNeedToConnect = int.Parse(Console.ReadLine());
        for (int i = 0; i < numberOfClientsYouNeedToConnect; i++)
        {
            Thread newThread = new Thread(new ThreadStart(Listeners));
            newThread.Start();
        }
    }
}
momo
  • 1
  • 1
  • 2
    You should make an attempt to convert it yourself, and then maybe we'll be able to help you with specific issues you encounter. Unfortunately, I don't think anybody here will convert it for you. – ProgrammingLlama Feb 21 '19 at 02:59
  • 1
    OK,thanks for help,I am newbie here,I will follow the rule in feature. – momo Feb 21 '19 at 03:02

1 Answers1

0

Check this project: https://github.com/nmalex/remote-maxscript.dlx

remote-maxscript.dlx is a 3dsmax MaxScript plugin that works as a remote MAXScript server inside of 3dsmax. You can Start/stop it with MAXScript commands, and communicate with the server over plain text protocol. Each request is treated as maxscript code, it will be executed, and result will be sent back over TCP.

Internally it runs TCP server, that does:

  • listens for incoming TCP connections,
  • receives plain text requests from the clients,
  • executes text commands as maxscript and returns results back.

Instead of making DLX plugin, you can wrap it into Console Application:

#include "stdafx.h"
#include "maxscript.server.h"

using namespace maxscript_server;

void HandleRequest(SOCKET clientSocket, const char* data) {
    printf("Received: %s\n", data);
    // TODO: handle data

    MAXScriptServer::Send(clientSocket, "OK"); // send back result "OK"
}

int main(int argc, char **argv)
{
    MAXScriptServer server((MAXScriptOutputCallback)&HandleRequest);
    server.Listen(29207);
    return 0;
}

What is left to do is to wrap C++ into C# library.

Alex Khoroshylov
  • 2,234
  • 1
  • 17
  • 28