# How to send data to and from java

**URL:** <https://forum.kirupa.com/t/how-to-send-data-to-and-from-java/258278>\
**Category:** Uncategorized\
**Created:** [April 22, 2008, 6:16pm UTC](https://forum.kirupa.com/t/how-to-send-data-to-and-from-java/258278 "2008-04-22T18:16:21Z")\
**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 22, 2008, 6:16pm UTC](https://forum.kirupa.com/t/how-to-send-data-to-and-from-java/258278/1 "2008-04-22T18:16:21Z")

</div>

Hey.  
As the title says im wondering what the fastest / best way to read and write data to flash from java is.

Currently im doing it this way.

[AS]  
// FLASH Sending message  
public function sendMessage( message:String ) {  
message = message + "  
";  
socket.writeUTFBytes( message ); // write string to socket  
socket.flush(); // makes sure it is sent right away  
}  
// Flash reading data  
private function socketData( event:ProgressEvent ):void {  
// read all data available and send string to function to take care of it  
receiveMessage( socket.readUTFBytes( socket.bytesAvailable ) );  
}  
[/AS]  
[AS]  
// JAVA reading data (this part is inside a thread)  
in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));  
String line;  
while((line = in.readLine()) != null){ // waits untill data is available  
de.takecareofmessage(line, mySocket);  
}  
//JAVA send data.  
public void sendData(Socket s, String data){  
try {  
// supposed to make window size infinite… no noticable effect  
s.setTcpNoDelay(true);  
PrintWriter out = new PrintWriter(s.getOutputStream());  
out.print(data); // write the string  
out.flush(); // make sure data is sent right away  
} catch (IOException e) {  
e.printStackTrace();  
}  
}  
[/AS]

This is working right now, and im receiving messages as they should be.  
As for speed and bandwidth utilization im not sure if its all that good?

id prefeer these methods to be as fast and bandwidth cheap as possible…  
Help please?
