Notifications
Clear all

[Closed] Socket communication between server and client via pure maxscript?

Hi,
I am looking for a socket communication between server and client example,there is an server example below this link:
https://forums.autodesk.com/t5/3ds-max-programming/unreliable-executed-code-though-dotnet-tcp-server/td-p/6379860
[Server Part]

fn createServer ipAddress port = 
(
	dotNetIPAddress = (DotNetClass "System.Net.IPAddress").Parse ipAddress
	tcpListener = DotNetObject "System.Net.Sockets.TcpListener" dotNetIPAddress port
	tcpListener.Start()s
	msgReceived = ""
	print ("listening on " + (ipAddress as string) + ":" + (port as string))
	while true do 
	(
		print("waiting for a client socket")
		socket = tcpListener.AcceptSocket()
		print("client socket accepted")
		while msgReceived != "exit" do
		(
			sendByteStream = DotNetObject "System.Byte[]" 10000
			socket.Receive sendByteStream
			encoding = DotnetClass "System.Text.UTF8Encoding"
			msgReceived = trimright (encoding.UTF8.GetString(sendByteStream))
			if msgReceived == "socketClosing" then (
				print("closing socket")
				socket.Close()
				exit
			)
			else (
				if msgReceived != "" then (
					print("execute : " + msgReceived)
					-- execute msgReceived
					try(
						result = execute(msgReceived)
					) catch (
						error_str = "" + getCurrentException() +"\n" 
						print(error_str)
					)
					-- send result
					ascii_encoder = dotNetObject "System.Text.ASCIIEncoding"
					bytes = ascii_encoder.GetBytes (result as string)
					result = socket.Send bytes
				)
			)
		)
	)
)

fn BackgroundTcpListenerDoWork theSender theEvent =
(
	ipAddress = "127.0.0.1"
	port = 7500
	try (
		createServer ipAddress port
		exit
	)
	catch(
		print("server crashed or port " + (port as string) + " is already used")
	)
)

BackgroundWorker = DotNetObject "System.ComponentModel.BackgroundWorker"
DotNet.AddEventHandler BackgroundWorker "DoWork" BackgroundTcpListenerDoWork
BackgroundWorker.WorkerSupportsCancellation = true
BackgroundWorker.RunWorkerAsync()

So how to use the pure maxscript for the Client part?Any help?Thanks in advance.

2 Replies
 ILS

See this scirpt:
http://rodrigopegorari.com/blog/?download=P5toMax_v1.0

It connects Processing to 3dsmax but the idea is the same . The client part is in maxscript so you can use that as a guide.

Thanks for the link, I ‘ll try it.