3 Replies Latest reply on Jun 19, 2006 4:12 PM by varomix

    sending data to SOCKET

    varomix
      HI guys

      I have this come from a JEdit plugin that sends data to MAYA trought a PORT, the code is python.

      Can I TRANSLATE this to AS3? can this be done in flex?
      here's the code

      # read whole buffer
      wholeText = (textArea.getText())
      # replace newline caracter with carriage return so it is properly sent to Maya
      wholeText = wholeText.replace('\n','\r')

      # connect to Maya through port 7092 and send data to it
      import socket
      maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      maya.connect("127.0.0.1", 7092)
      maya.send(wholeText)

      I asume that it is possible, gonna keep testing If u now how, please let me knoe
        • 1. Re: sending data to SOCKET
          varomix Level 1
          OK I made it work in Flash 8 with this code yeah!!!!

          var socket:XMLSocket = new XMLSocket();
          socket.connect("127.0.0.1", 7092);
          socket.onConnect = function(success) {
          var mel = "polyCube";
          trace("GO Check Maya");
          socket.send(mel);
          };

          but that is not working in FLEX
          how will I do that in FLEX??

          thenx
          • 2. Re: sending data to SOCKET
            Level 7
            varomix wrote:
            > OK I made it work in Flash 8 with this code yeah!!!!
            >
            > var socket:XMLSocket = new XMLSocket();
            > socket.connect("127.0.0.1", 7092);
            > socket.onConnect = function(success) {
            > var mel = "polyCube";
            > trace("GO Check Maya");
            > socket.send(mel);
            > };
            >
            > but that is not working in FLEX
            > how will I do that in FLEX??
            >
            > thenx
            >

            You can do something like this
            package
            {
            import flash.events.*;
            import flash.net.XMLSocket;

            public class MySocketClass
            {
            private var socket:XMLSocket;

            public function send(data:Object):void
            {
            socket.send(data);
            }

            public function MySocketClass():void
            {
            var socket:XMLSocket = new XMLSocket();
            socket.connect("127.0.0.1", 7092);
            socket.addEventListener(Event.CONNECT, connectHandler);

            }

            public function connectHandler(event:Event):void
            {
            var mel:String = "polyCube";
            trace("GO Check Maya");
            send(mel);

            }
            }
            }

            Winsha
            • 3. sending data to SOCKET
              varomix Level 1
              Hey thenx a lot I did some work in the weekend and did this simpler function which is not much diferent than the flash version

              //// SENDING THE DATA TO MAYA


              public function SendData():void{

              var socket:XMLSocket = new XMLSocket();
              socket.connect("127.0.0.1", 7092);

              var DaMel:String = inField.text;
              socket.send(DaMel);
              //var mel:String = "polyCube -sx 10 -sy 15 -sz 5 -h 20;";
              }

              and not much different than the class u did.
              I don;t use classes much, how will I use the class u did for a button click??

              thenx