Advertisement
kasru

Basic Networking

Jan 31st, 2013
5,493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler  ******
  3.  
  4. #pragma strict
  5.  
  6. var ipAddress : String = "127.0.0.1";
  7. var port : int = 25000;
  8. var maxConnections : int = 10;
  9.  
  10. function OnGUI () {
  11.  
  12. GUILayout.BeginHorizontal ();
  13. ipAddress = GUILayout.TextField (ipAddress);
  14. GUILayout.Label ("IP ADDRESS");
  15. GUILayout.EndHorizontal ();
  16.  
  17. GUILayout.BeginHorizontal ();
  18. var tempPort : String;
  19. tempPort = GUILayout.TextField (port.ToString());
  20. port = parseInt(tempPort);
  21. GUILayout.Label ("PORT");
  22. GUILayout.EndHorizontal();
  23.  
  24. if(GUILayout.Button ("CONNECT")) {
  25. print("connecting... ");
  26. Network.Connect (ipAddress, port);
  27. }
  28.  
  29. if(GUILayout.Button ("START SERVER")) {
  30. print("starting server on " + ipAddress + ":" + port);
  31. Network.InitializeServer (maxConnections, port);
  32.  
  33. }
  34.  
  35.  
  36. }
  37.  
  38. function OnConnectedToServer () {
  39. print("connected");
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement