# Connect to socket, read and write data

**URL:** <https://forum.kirupa.com/t/connect-to-socket-read-and-write-data/257575>\
**Category:** Uncategorized\
**Created:** [April 15, 2008, 1:21pm UTC](https://forum.kirupa.com/t/connect-to-socket-read-and-write-data/257575 "2008-04-15T13:21:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wokawaka](https://avatars.discourse-cdn.com/v4/letter/w/e480ec/32.png) [@wokawaka](https://forum.kirupa.com/u/wokawaka)\
**Post date:** [April 15, 2008, 1:21pm UTC](https://forum.kirupa.com/t/connect-to-socket-read-and-write-data/257575/1 "2008-04-15T13:21:47Z")

</div>

Hi.  
Im playing around with a flash game idea of mine.  
Trying to connect the flash file to my java socket server.  
Having a few problems as it seems the flash file will not output data from the socket when i know its being written (well pretty sure atleast).

The java server recognizes the connection and sends a request for a password to the client but the _**private function handleData(msg) {**_ does not seem to get this request.

What did i do wrong?  
Heres my current class file

Thanks  
//Woka  
[AS]  
package AS.socket{  
import flash.errors._;  
import flash.events._;  
import flash.net.Socket;

```
import AS.encryption.*;  

public class socketConnector2 {
    private var encrypter:rot; 
    public function socketConnector2(en:rot) {
        
        encrypter = en;
        
        var host:String="127.0.0.1";
        var port:int=9765;

        var connection=new Socket();
        connection.connect(host, port);
                    
        connection.addEventListener(Event.CLOSE, handleDisconnect);
        connection.addEventListener(Event.CONNECT, handleConnection);
        connection.addEventListener(ProgressEvent.SOCKET_DATA, handleData);
    }
    
    private function handleConnection(success) {
        trace("connected");
    }
    
    private function handleData(msg) {
        trace("Data: " + msg);
    }
    
    private function handleDisconnect() {
        trace("disconnected");
    }
}

```

}  
[/AS]

P.S. if anyone would like to take the time to explain to me how i should send data to and from the client id be much obliged. I’ve heard its not good to send strings of the data…  
was considering sending things like \*\*/c 123.4 324.1 \*\*to the server were the /c tells the server its a coordinate and the following two terms are the x and y coordinates. Whys that bad? (and if its bad what should i do?)
