Search Unity

Socket Wrong Connection and Timeout Problem.

Discussion in 'Multiplayer' started by dalanchoo, Apr 4, 2017.

  1. dalanchoo

    dalanchoo

    Joined:
    Jun 6, 2014
    Posts:
    44
    Hi. I am having some issues with sockets disconnecting due to a timeout.

    I have 3 different programs talking to each other using sockets. The Command Center (CC) sends messages to the Modal Manager (MM). The Modal Manger can send messages to the VR App. I have this working to the point where the Command Center (running on my PC) can send a message to the Modal Manager (running on my Android device), to launch another app. I can then send a message from the Command Center to the Modal Manages asking it to kill the app it launched, and that works fine.

    Now I wanted to add a response from the Modal Manger to the Command Center. Basically, I just want the Command Center to ask the Modal Manger to report the temperature. I thought that this would be simple enough, but when the Modal Manger receive the message from the Command Center, it reports that there is a timeout on the socket.

    One interesting thing is that if I run both the Modal Manager and the Command Center on my PC in the editor, everything seems to work fine. I just change the IP addresses of both to 127.0.0.1

    So it seems like I am passing messages in one direction correctly, but my response causes the issue.

    The relevant code is attached.

    This is my log from ADB Logcat

    04-04 14:53:18.131 24916-24931/? I/Unity: Creating NetworkCommandManger thread
    04-04 14:53:23.301 24916-24931/? I/Unity: localPort is 9001
    04-04 14:53:23.301 24916-24931/? I/Unity: remotePort is 9000
    04-04 14:53:23.301 24916-24931/? I/Unity: name is CC Socket
    04-04 14:53:23.337 24916-24931/? I/Unity: CC Socket: Socket Open. socketId is: 0
    04-04 14:53:23.338 24916-24931/? I/Unity: CC Socket: Connected. connectionId: 1
    04-04 14:53:23.338 24916-24931/? I/Unity: localPort is 8888
    04-04 14:53:23.338 24916-24931/? I/Unity: remotePort is 8889
    04-04 14:53:23.338 24916-24931/? I/Unity: name is VR App Socket
    04-04 14:53:23.340 24916-24931/? I/Unity: VR App Socket: Socket Open. socketId is: 1
    04-04 14:53:23.340 24916-24931/? I/Unity: VR App Socket: Connected. connectionId: 1
    04-04 14:53:24.860 24916-24973/? I/Unity: CC Socket: Incoming connection event received
    04-04 14:53:29.381 24916-24973/? I/Unity: CC Socket: Incoming message event received: {"command":"ModalVR.GetTemp"}
    04-04 14:53:29.384 24916-24973/? I/Unity: ParseDataEvent Received: {"command":"ModalVR.GetTemp"}
    04-04 14:53:29.433 24916-24973/? I/Unity: WrongConnection: CC Socket: SocketConnection.SendMessageCommon
    04-04 14:53:41.476 24916-24973/? I/Unity: Timeout: CC Socket: SocketConnection.Receive
    04-04 14:53:41.478 24916-24973/? I/Unity: CC Socket: Remote client event disconnected
    04-04 14:53:41.478 24916-24973/? I/Unity: Timeout: VR App Socket: SocketConnection.Receive
    04-04 14:53:41.478 24916-24973/? I/Unity: VR App Socket: Remote client event disconnected

    Thanks in advance for any help.
    John Lawrie
     

    Attached Files:

    Last edited: Apr 4, 2017
  2. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Hi @dalanchoo, could you connect directly to me, looks like i need to debug your code. AFAIK, to repro this problem I need only CC and MM? Could you please simplify your project a little bit, if yiu can i will take a loon on weekend

    =Alex
     
  3. dalanchoo

    dalanchoo

    Joined:
    Jun 6, 2014
    Posts:
    44
    I was able to figure this out. I had to have only the client do socket connections, and have the host then use the receive connection ID to send messages back. I was doing a connection on both sides of the socket, and the connection ID returned from the connect command was not the same as what was received from the receive command.

    Thanks anywaay.
    John Lawrie.
     
    aabramychev likes this.