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 carloskassis · Jan 22, 2018 at 04:03 PM · socketsocketsudp

C# UDPClient not receiving packets over external IP

So here's the thing, i'm creating a server/client environment for a game where a port forwarded computer acts as a server, and clients send the first UDP message to connect and get the accept message then start sending the in-game UDP messages after successfully connecting. The problem is, when I use the local IPs say the server using 10.0.0.7 and a client is using 10.0.0.4, everything works just fine:

  1. Client sends connect message.

  2. Server receives it.

  3. Servers sends back accept message.

  4. Client receives it

  5. All further messages reach both ends without any problem.

But when I use the external IP:

  1. Client sends connect message.

  2. Server receives it.

  3. Servers sends back accept message.

  4. Client receives it

  5. Both ends can send messages but the client doesn't receive any more messages.

Wanted to know at the end if the problem is somehow from the code, or from what I think it's really from, router, NAT, firewalls or anything like that. (Note: Client sends to server's 8888 port, and server sends back through the client's local port, as it should be.)

Below is the client code:

 void Start()
 {
     client = new UdpClient();
     client.Connect(IPAddress.Parse("<Global IP>"), 8888);
     client.BeginReceive(new AsyncCallback(ReadMessage), client);
 }
 
 private void ReadMessage(IAsyncResult result)
 {
     IPEndPoint ipEndPoint = null;
     string message = Encoding.ASCII.GetString(client.EndReceive(result, ref ipEndPoint));
     print("Got: " + message);
     string[] wholeMessages = message.Split('#');
     for (int w = 0; w < wholeMessages.Length - 1; w++)
     {
 
 
         string[] parts = wholeMessages[w].Split('$');
         if (!connected && parts.Length == 3 && parts[0] == "accept" && int.TryParse(parts[1], out ID))
         {
             connected = true;
             code = parts[2];
         }
     }
     client.BeginReceive(new AsyncCallback(ReadMessage), client);
 }
 
 public void SendUDP(string message)
 {
     client.Send(Encoding.ASCII.GetBytes(message), message.Length);
 }
 





Comment
Add comment · Show 4
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 Aurelius_erforscht_das_Netz · Jun 04, 2018 at 11:00 AM 0
Share

Did you find a solution to your issue?

avatar image unity_4J-FEv3jCWkBSQ · Jan 30, 2020 at 11:14 AM 0
Share

Did you get the solution for your issue?

avatar image Aurelius_erforscht_das_Netz unity_4J-FEv3jCWkBSQ · Jan 30, 2020 at 12:17 PM 0
Share

I got an answer in the Unity Discord but didn't find the source to back it up. Nevertheless it ended up being true for me:

In the editor, Unity blocks all connections to external IPs. But when built, the game is capable of connecting to external IPs. So what I ended up doing is to write a small python script which receives external UDP messages and forwards them via the local IP. That was sufficient for development. Before building I changed the socket to the external IP/Port and the built game behaved like expected.

Hope that helps

Link to the stack overflow question with the python code.

avatar image carloskassis Aurelius_erforscht_das_Netz · Jan 30, 2020 at 05:20 PM 0
Share

Hey! Damn it's been 2 years since i've worked on this project. Indeed the problem occurred when I sent a UDP or TCP packet from my pc over to my external IP which my computer received according to Wireshark but silently ignored it. So apparently you can't send stuff to your device using your external IP, I never needed to cause' the program would later be ran on a server not a local pc. In the end I made the the server and client programs work over Local IP, and when I wanted to send client to my friends to test, I sent them a build that works on external IP. Sorry for not writing the solution and closing the thread, I was new to forums back then. Thanks for the reply!

0 Replies

· Add your reply
  • Sort: 

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

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

Solved Webcamtexture 0 Answers

Unity Editor has not permission on UDP port 2 Answers

How do I use a c# library in unity? 1 Answer

Weird string compare behaviour with socket 0 Answers

Socket.io, connetion works but can't emit 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