Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Mabulhuda · Sep 17, 2015 at 08:16 AM · c#androidnetworkingtcpip

TCP/IP Unity Android ERROR Helfe

Hey all I am making a android game using unity3d, I want to control my game from my laptop I made a TCP/IP chat like program to get the input from my keyboard to my android over internet I made one for my Laptop (Windows form APP) and one for Unity, everything works except for one little annoying error.

ERROR: I want when I press the X button to move a sphere from point A to point B but when send the "x" value it says :

INTERNAL_get_position can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

and when I close the Windows form APP the ball then moves what to do I tried the Awake and the start functions too.

PS: I am testing this on the same computer so its not about the IPAddresses.

here is my code for the unity part:

     using UnityEngine;
         using System.Collections;
         using System.Text;
         using System;
         using System.Net;
         using System.Net.Sockets;
         public class CHAT : MonoBehaviour {
    
 
      private Socket sck;
         EndPoint epLocal, epRemote;
     
         //Gameobjects
        public Transform ball , point;
         //logic
       static Boolean arreivedX = false;
        string xIsHere;
         // Use this for initialization
         void Start () {
             
         sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
         sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
         epLocal = new IPEndPoint(IPAddress.Parse("192.168.1.9"), Convert.ToInt32("81"));
         sck.Bind(epLocal);
         epRemote = new IPEndPoint(IPAddress.Parse("192.168.1.9"), Convert.ToInt32("80"));
         sck.Connect(epRemote);
         Debug.Log("COnnected");
         byte[] buffer = new byte[1500];
         sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCAllBack), buffer);
   
     }
 
     void Awake()
     {
        
         
     }
     
     // Update is called once per frame
     void Update () {
 
         if (arreivedX)
         {
             ball.position = Vector3.MoveTowards(ball.position, point.position, 5 * Time.deltaTime);
             
         }
     }
 
   private void MessageCAllBack(IAsyncResult aResult)
     {
         try
         {
             int size = sck.EndReceiveFrom(aResult, ref epRemote);
 
             if (size > 0)
             {
                 byte[] receivedData = new byte[1464];
                 receivedData = (byte[])aResult.AsyncState;
 
                 ASCIIEncoding eEncoding = new ASCIIEncoding();
                 string receivedMessage = eEncoding.GetString(receivedData);
                //bn3mal if statement bnshof weslat el X wela la2 w iza weslat bnmasi el tabeh
                
                 if (receivedMessage.Contains("x"))
                 {
                     Debug.Log("X is here");
                    
                     arreivedX = true;
                    
                 }
                
                 //b3deen bntba3 el msg bs b7aletna bdna n5li el touch active.
                 //ListMessage.Items.Add("Sender:" + receivedMessage);
             }
 
             byte[] buffer = new byte[1500];
             sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCAllBack), buffer);
 
         }
         catch(Exception exp)
         {
             Debug.Log(exp.ToString());
         }
 
     }
     
 }


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 Suddoha · Sep 17, 2015 at 11:19 AM 0
Share

The error messages complains about an issue related to threading. I assume that has something to do with the asynchronous BeginReceiveFrom that you're trying to perform.

Try to do a synchronous receive first, and then check whether the error still occurs. If not, try to figure out which lines causes the error to happen.

1 Reply

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

Answer by Mabulhuda · Sep 21, 2015 at 11:14 AM

http://stackoverflow.com/questions/32605647/tcp-ip-unity-android-error-helfe

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

32 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 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

Determine Wifi adapter address on Android 0 Answers

Send variables from client to server 0 Answers

[HELP] Problem in multiplayer networking code in c# 0 Answers

Disable/Enable Firebase Notifications 0 Answers

Day/Night cycle turns black at night and how to Serialize it rightly? 0 Answers


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