Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to set a timeout value for tcpListener with MaxScript

How to set a timeout value for tcpListener with MaxScript

YASUSHI_EMOTO
Enthusiast Enthusiast
1,016 Views
2 Replies
Message 1 of 3

How to set a timeout value for tcpListener with MaxScript

YASUSHI_EMOTO
Enthusiast
Enthusiast

TCP servers have something called a "timeout value".

I want MaxScript's TCP server to have a timeout value.

https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.receivetimeout?view=net-6.0

 

Is there a way to set a timeout value for the following code?

 

dotNetIPAddress = (DotNetClass "System.Net.IPAddress").Parse "127.0.0.1"
tcpListener = DotNetObject "System.Net.Sockets.TcpListener" dotNetIPAddress 8888
tcpListener.Start()s
socket = tcpListener.AcceptSocket()

while true do
(
   sendByteStream = DotNetObject "System.Byte[]" 10000
   socket.Receive sendByteStream
   encoding = DotnetClass "System.Text.UTF8Encoding"
   msgReceived = trimright (encoding.UTF8.GetString(sendByteStream))
)
0 Likes
Accepted solutions (1)
1,017 Views
2 Replies
Replies (2)
Message 2 of 3

istan
Advisor
Advisor
0 Likes
Message 3 of 3

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

Your question is not clear to me as it is asked...

ReceieveTimeout and SendTimeout are a TcpClient properties those, once set, affect the behavior of the TcpClient read and send methods:

tcp_client = dotnetobject "System.Net.Sockets.TcpClient"
tcp_client.ReceiveTimeout = 500

 

nothing extra needed here from the MXS code side 

0 Likes