3ds Max Script socket receving data via .net api

做個紀錄

socket = dotNetObject "System.Net.Sockets.Socket" (dotnetclass "System.Net.Sockets.AddressFamily").InterNetwork (dotnetclass "System.Net.Sockets.SocketType").Stream (dotnetclass "System.Net.Sockets.ProtocolType").Tcp

socket.connect ip_address port

buf = DotNetObject "System.Byte[]" 1000

fn doFaceShiftSocket =
(	
	try
	(
		while socket.Connected == true do
		(
			socket.Receive buf
		)
	)
	catch
	(
		-- do nothing
	)
)
thread = dotNetObject "system.componentModel.backgroundWorker"
dotnet.addEventHandler thread "DoWork" doFaceShiftSocket
thread.WorkerSupportsCancellation = true
thread.runWorkerAsync()

for i=0 to (buf.length-1) do
		print (buf.GetValue i)

-- close socket
socket.close()