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
1
Question by eaglemaster7 · Jan 31, 2012 at 05:55 AM · networkinginternet

how to Ping Google.com

i want to check internet speed to google, then how to get return value of ping time? i can't figure out the syntax so i tried :

 function  Update(){
 Debug.Log(Ping("www.google.com").time);}

but debug always return -1, please give me help of sample script..

Comment
Add comment
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

1 Reply

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

Answer by syclamoth · Jan 31, 2012 at 06:01 AM

The correct usage of 'Ping' is asynchronous- what you're trying to do here is start a fresh Ping every frame, without waiting for it to return anything!

Instead, use it like this:

function Start() { PingGoogle(); }

function PingGoogle() { var googPing : Ping = new Ping("74.125.224.72"); // keep in mind that 'Ping' only accepts IP addresses, it doesn't // do DNS lookup. This address may not work for your location- // Google owns many servers the world over.

 while(!googPing.isDone)
 {
     yield;
 }
 Debug.Log(googPing.time);

}

Comment
Add comment · Show 7 · 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
avatar image eaglemaster7 · Jan 31, 2012 at 06:27 AM 0
Share

O$$anonymous$$ thanks a lot, btw you missed "new" before Ping("74.125.224.72")

avatar image syclamoth · Jan 31, 2012 at 06:51 AM 0
Share

Sorry, I always forget where it's necessary in JS. It's easy in C#- just use them everywhere...

avatar image naglers · Oct 30, 2013 at 02:30 PM 2
Share

in c# for people: Ping GooglePing = new Ping("74.125.224.72"); while(!GooglePing.isDone) { yield return null; }

avatar image djkr · Jan 02, 2014 at 08:36 PM 0
Share

Hello! This JS was really helpful - but does anyone know how to take the result 'googPing.time' into a FLOAT or an INT?

I tried many times, but I always get '0' as the result.

I'm going to ping my own server, then I'm needing to put a time delay, calculated - it will take the ping value - for ex. 80, then divide it by 8, resulting with the value 10 - then put a delay for 10 seconds - which is about how much time my assets need to load (in extensive tests done), at that (ping/based) speed.

I've tried: ... Debug.Log(googPing.time);

 goog = parseInt(googPing.time);
 yield goog;

}

but then goog can not be used as a divider - such as:

var divider = 8;

timer = ( goog / divider); //Divides goog by 8

//unfortunately the result is always 0

avatar image col000r · Aug 22, 2014 at 09:06 PM 2
Share

If you're trying to ping your Amazon AWS EC2 instance and get a reply of -1, make sure you add this Inbound rule to your Security Group: Custom IC$$anonymous$$P Rule: ECHO REQUEST, Source: Anywhere. Or you will simply not get a reply and thus get a ping.time of -1

Show more comments

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

8 People are following this question.

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

Related Questions

Unity networking tutorial? 6 Answers

Is it possible to check internet conneciton for WWW class downloading ? 3 Answers

Unity multiplayer over internet does not work using port forwarding 1 Answer

Connecting to custom Master Server over the internet 1 Answer

How does/can Unity handle offline sync with backend? 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