Author Topic: Sending nulls as parameters to RFCs  (Read 1869 times)

BumpkinRich

  • Guest
Sending nulls as parameters to RFCs
« on: November 10, 2013, 08:40:57 AM »
I'm porting from Unity's networking to TNet and had a problem due to sending NULL values as a parameter.

Hopefully this might shed some light on anyone else having the problem.

There's a gotcha in the Write(BinaryWriter bw, params object[] objs) method - the Debug.LogError that tells you if it cannot write the type does not get called if the value is null.  The parameter is effectively ignored so it cannot be reconciled later on.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sending nulls as parameters to RFCs
« Reply #1 on: November 10, 2013, 09:48:19 AM »
That's correct. You can't pass a null. Why would you want to send a null? Furthermore, null implies a reference, implying a class. You can't send custom classes across the network, only their base data types like float, int, vector, etc.

BumpkinRich

  • Guest
Re: Sending nulls as parameters to RFCs
« Reply #2 on: November 10, 2013, 12:11:36 PM »
I need to send NULL in one exceptional circumstance, which saves me duplicating lots of code over and over or having multiple if statements / long case statements.

I am implementing a multiple network solution... solution.  So you can use Unity, TNet, Photon and others.  As Unity allows you to pass a NetworkView object I need to pass a null if their networking solution is not being used.

I overcame this with TNet by adding a null into the write method with a '!' prefix.

Just wanted people to be aware that the warning message that you cannot send a NULL never gets hit.  It would have been really useful if it did  ;)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sending nulls as parameters to RFCs
« Reply #3 on: November 11, 2013, 12:07:54 PM »
Problem with passing a "null" is that its type is unknown. Anything can be a null, so TNet wouldn't be able to figure out what it is you're trying to send.