Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Java Server for Actionscript 3.0--Starting Help Posted by TuxBobble on 8 Dec 2009 at 10:56 PM
I'm working on a game in Flash/AS3. The idea is to have a multiplayer game running using Flash clients, and a Java server for synchronization.

As of right now I'm a LONG way away from accomplishing that goal. I've used Java before, but not in a while so I'm rusty. And at that, I hadn't ever really done java.net stuff before, but I'm trying to brush up and learn a few things in the process.

So, I found this Java server/client pair from http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

I tried trimming the server down (I don't want any Knock Knock jokes right now lol) to communicate with AS3 using AS3's XMLSockets class. As of right now, I'm trying to figure out which side is causing the problem, so I had to choose between Java and AS forums for this post. I'm trying here first since I'm a bit more familiar with AS3 so I want to check that I'm doing things right on the Java side first.

try{
				//auto-flushing PrintWriter on client's outputstream
				PrintWriter out = new PrintWriter(clntsocket.getOutputStream(), true);
				BufferedReader in = new BufferedReader(new InputStreamReader(clntsocket.getInputStream()));
				String inputLine;
				inputLine = in.readLine();
				if(inputLine != null){
					System.out.println(inputLine);
					out.println("Received OK!");
				}
			}
			catch(Exception e){
				System.out.println("WTF");
			}


I want to verify that I'm doing things right. The PrintWriter auto-flushes the stream, as far as I can tell. BufferedReader works fine, and the console print of inputLine works, so it's not missing the conditional statement or anything like that. But I can't seem to figure out how to transmit (or perhaps simply receive) the PrintWriter's flushed println. If anyone has any tips about what I'm doing here please let me know. The whole try-catch section is in a while() to keep it looping--not sure if that affects anything the way java.net transmits.


UPDATE: I found the issue. Apparently on the Java side you need to terminate with a \0 at the end of the transmission. That seems to allow for recognition of the transmission.

Any tips on XML format manipulation on the server side? Or should I just pass the "meat" of the XML, and receive it back into the same location to upadte the XML?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.