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 spike35031 · Jun 11, 2012 at 12:09 AM · networkingnetworkcommunicationsocketsudp

Problems with UDP data sending

Whenever I run my GUI script, I keep getting the error "SocketException: The requested address is not valid in its context." on line 35 and when I press the "Sign in" button, I get the error "SocketException: An invalid argument was supplied." on line 61. I've been working on this for at least three hours strait to no avail. Hopefully someone else can figure it out!

here's the code:

 using UnityEngine;
 using System.Collections;
 using System.Net;
 using System.Net.Sockets;
 using System;
 using System.Linq;
 using System.Text;

 public class LoginGUI : MonoBehaviour {
 
 public static int myRecPort;// = 1234;
 public static int mySendPort = 1235;
 public static string ServerIPAddress = "255.255.255.255";
 private Rect loginWindowRect = new Rect (20, 20, 300, 250);
 private string UsernameField = "Username";
 private string PasswordField = "Password";
 private string reply;
 
     //Communication setup
     System.Net.Sockets.UdpClient sock = new System.Net.Sockets.UdpClient();
         IPEndPoint iep = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1235);
         byte[] SendData = new byte[9999];
     
     //recieve
     int recv;
     byte[] RecData = new byte[9999];
     IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1234);
     Socket newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     IPEndPoint sender = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1234);
     EndPoint tmpRemote;
 
 
 void Start () {
     tmpRemote = (EndPoint)sender;
     newSocket.Bind(endpoint);
     Debug.Log("connected");
 }
 
 void OnGUI () {
     loginWindowRect = GUI.Window (0, loginWindowRect, LoginWindow, "Login");
     
 }
 
 void LoginWindow (int windowID) {
     GUI.Label(new Rect (25, 25, 100, 30), "Username: ");
     GUI.Label(new Rect (25, 60, 100, 30), "Password: ");
     UsernameField = GUI.TextField (new Rect (125, 25, 150, 20), UsernameField);
     PasswordField = GUI.PasswordField (new Rect (125, 60, 150, 20), PasswordField, "*"[0]);
     
     if (GUI.Button (new Rect(25, 100, 250, 30), "Sign in")) {
         reply = SendReceive("Login(" + UsernameField + ")[" + PasswordField + "]");
         Debug.Log("sent login");
     }
     GUI.DragWindow(new Rect(0, 0, 10000, 10000));
 }
 
 string SendReceive(string message)
 {
     SendData = Encoding.ASCII.GetBytes(message);
     sock.Send(SendData, SendData.Length, iep);
     recv = newSocket.ReceiveFrom(RecData, ref tmpRemote);
     return Encoding.ASCII.GetString(RecData);
 }
 }
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 sandyakayika5730 · Sep 28, 2020 at 05:40 PM 0
Share

@Bertitid

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by spike35031 · Jun 11, 2012 at 05:03 AM

Somehow got it to work by copy-pasting it into a new class file. Not sure why it worked though...

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UDP Sockets for networking, getting overloaded?? 0 Answers

Connect to non-unity server with LLAPI 0 Answers

Networking source for new networking example 0 Answers

How do I identify if the packet arrived by UDP or TCP protocol 1 Answer

Which ways are available for a Unity program to communicate with other programs? 2 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