Unity3D Network ReadMessage -
how check error if client trying connect absent server?
my code!
//server void start () { networkserver.listen(13044); } //client networkclient thisclient = new networkclient (); thisclient.connect ("127.0.0.1", 13044); thisclient.registerhandler(msgtype.error, errortest); thisclient.registerhandler (msgtype.disconnect, dctest); void errortest(networkmessage netmsg){ var errormsg = netmsg.readmessage<errormessage>(); debug.log("error:" + errormsg.errorcode);} void dctest(networkmessage netmsg){ //if run client while server not present, goes here instead of errortest }
you using readmessage errormessage, errormessage valid in error messages (onerror).
your dctest function triggered on disconnection, not on error.
disconnect special msgtype (see https://docs.unity3d.com/scriptreference/networking.msgtype.html) (if remember) doesn't contain data.
so answer question : have result. in netmsg.
https://docs.unity3d.com/manual/unetmessages.html
the readmessage function used own networkmessages, when wand send/read custom data.
Comments
Post a Comment