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
2
Question by santiago_sgk · Sep 23, 2014 at 05:37 PM · c#socketudp

C# code run in App Console but not on Unity console

Hi guys! First, sorry for my english. Now, I have a problem with a code which uses sockets. I want connect my script over IPv6 but I receive a SocketException when I run this script in Unity. The next code works perfect as a Console Application Project in MonoDevelop.

             Socket s;
             s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
             IPAddress ip = IPAddress.Parse("ff15::2");
             s.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption(ip));
             IPEndPoint ipep = new IPEndPoint(IPAddress.IPv6Any, 26000);
             s.Bind(ipep);
             
             while (true) {
                 byte[] b = new byte[1024];
                 if (s == null)
                     Console.WriteLine ("S es null");
                 else
                     s.Receive (b);
                 string str = System.Text.Encoding.ASCII.GetString (b, 0, b.Length);
                 Console.WriteLine (str.Trim ());
             }
         }

But the same code (I only changed "Console.WriteLine()" for "Debug.Log()") doesn't work as Unity Project. This code break with the exception: "SocketException: An address incompatible with the requested protocol was used." Can someone help me? Thanks!

Santiago.

Comment
Add comment · Show 6
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 tanoshimi · Sep 23, 2014 at 05:44 PM 0
Share

Is this for web player? I don't think the security sandbox will allow you to create listening sockets there.

avatar image santiago_sgk · Sep 23, 2014 at 06:07 PM 0
Share

No, it isn't for web player.

avatar image SnotE101 · Sep 23, 2014 at 09:41 PM 0
Share

What does it say on the top of your code, where it says using ....

avatar image santiago_sgk · Sep 24, 2014 at 05:42 PM 0
Share

Sorry, I forgot add the libraries at the top of the code:

using UnityEngine; using System.Net; using System.Net.Sockets; using System.Net.NetworkInformation;

avatar image Kender · Jul 23, 2016 at 02:26 AM 0
Share

Having almost same issue.

 m_socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.Add$$anonymous$$embership, new IPv6$$anonymous$$ulticastOption(IPAddress.Parse("FF02::1")));


 SocketException: The requested address is not valid in its context.
 
 System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, System.Object optionValue)


 $$anonymous$$essage: The requested address is not valid in its context.
 Source: System
 TargetSite: Void SetSocketOption(SocketOptionLevel, SocketOptionName, System.Object)
 ErrorCode: 10049
 NaticeErrorCode: 10049
 SocketErrorCode: AddressNotAvailable

Perfectly works in Console application, does not work in Unity.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kew2001 · May 13, 2017 at 09:27 AM

Same. Did anyone ever get to the bottom of this?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

UDPSend not working with iPad over LAN 0 Answers

UDP implementation in Unity, unable to send to two different machines 0 Answers

Receiving UDP data in Unity? 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