Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sdgd · Aug 21, 2013 at 09:36 AM · c#networking

how to send data from client to client?

I'm trying to send data directly to other specific client and not all clients without interrupting the server's bandwidth.

and here's how I'm trying to do it atm.

 Sending RPC failed because 'P2PMessage' parameter 0 (UnityEngine.NetworkMessageInfo) is not supported.
 UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
 Server:OnGUI() (at Assets/Networking/Server.cs:29)

Server Script:

 private NetworkMessageInfo Info1;
 private NetworkMessageInfo Info2;
 
 
 
 
     void OnGUI (){
         
         if (Network.peerType == NetworkPeerType.Disconnected){
             if (GUILayout.Button("Start Server")){
                 Network.InitializeServer(10, Port);
             }
         }
         else {
             GUILayout.Label("Server");
             GUILayout.Label("Connections: " + Network.connections.Length);
             if (GUILayout.Button("Logout")){
                 Network.Disconnect(5);
             }
         }
         if (GUILayout.Button("send infos")){
             networkView.RPC("P2PMessage", RPCMode.All, Info1, Info2);
         }
     }
 
 
 
 
 
 [RPC]
 void Register (string UserName, string Password, NetworkMessageInfo Info){
     Info1 = Info;
 }
 [RPC]
 void LogIn (string UserName, string Password, NetworkMessageInfo Info){
     Info2 = Info;
 }

Client Full Script:

 using UnityEngine;
 using System.Collections;
 
 public class Client : MonoBehaviour {
     public GameObject Planet;
     public string IP = "31.15.149.40";
     public int Port = 25001;
     
     private string UserName = "Username";//||Email";
     private string UserPass = "";
     
     string type = "";
     bool works = false;
     bool P2P = false;
     NetworkMessageInfo Info1;
     NetworkMessageInfo Info2;
 //    int MyNetworkInt = 0;
     
     void Start (){
         Network.Connect(IP, Port);
     }
     
     void OnGUI (){
         if (Network.peerType == NetworkPeerType.Disconnected){
             if (GUILayout.Button("Reconnect")){
                 Network.Connect(IP, Port);
             }
         }
         
         // enter username
         GUILayout.BeginHorizontal();
             GUILayout.Label("User Name");
             UserName = GUILayout.TextField(UserName, GUILayout.MinWidth(50));
         GUILayout.EndHorizontal();
         
         // enter password
         GUILayout.BeginHorizontal();
             GUILayout.Label("Password");
             UserPass = GUILayout.PasswordField(UserPass,'*', GUILayout.MinWidth(30));
             GUILayout.Label("" + UserPass.Length);
         GUILayout.EndHorizontal();
         
         // login || register
         
         if (! (Network.peerType == NetworkPeerType.Disconnected)) {
             GUILayout.BeginHorizontal();
                 if (GUILayout.Button("Login")){
                     networkView.RPC("LogIn", RPCMode.Server, UserName, UserPass);
                 }
                 if (GUILayout.Button("Register")){
                     networkView.RPC("Register", RPCMode.Server, UserName, UserPass);
                 }
             GUILayout.EndHorizontal();
             GUILayout.Label(type + works);
             GUILayout.Label("P2P is " + P2P);
             if (GUILayout.Button("Send true To Client 1 and mark mine false") ){
                 P2P = false;
                 networkView.RPC("P2Pmessage", Info1.sender, true);
             }
             if (GUILayout.Button("Send true To Client 2 and mark mine false") ){
                 P2P = false;
                 networkView.RPC("P2Pmessage", Info2.sender, true);
             }
         }
     }
 
     

     [RPC]
     void P2PMessage (NetworkMessageInfo inf1, NetworkMessageInfo inf2){
         Info1 = inf1;
         Info2 = inf2;
     }
     [RPC]
     void ReturnTF (string tip, bool TF){
         works = TF;
         type = tip;
     }
 }

I gave client full because I think all info is important, ...

thanks in advance.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Aug 21, 2013 at 11:27 AM 1
Share

Network$$anonymous$$essageInfo isn't a supported parameter type because it is "made" by the networking system and appended to any RPC call you write should you specify it as the last parameter.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by KiraSensei · Aug 21, 2013 at 11:40 AM

RPC calls accept only a few parameter : int, float, string, NetworkPlayer, NetworkViewID, Vector3, Quaternion.

It accepts NetworkMessageInfo only for the last argument, and it contains informations about who sent the call.

Have a look at the doc here.

You also send a boolean (lign 58 and 62), but your method P2PMessage does not have any boolean arg.

You should have :

 [RPC]
 void P2PMessage (boolean myBool, NetworkMessageInfo info)
 {
    ...
 }

You may need another argument to know if it is client 1 or 2 to valuate Info1 or Info2 (It depends on what you really want to do with this information...)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Networking how to return data? OR how to send only to 1 client 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Since switching to using offline & online scenes in the NetworkManager, Clients will not sync (UNET) 0 Answers

How do I Assign client authority to a gameobject? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges