Multiplayer Flash Game with Java Server problems
Alright, basically I've been trying to find out how to set up a
multiplayer flash game, recently I have concluded to code my own server
using Java. I have finally managed to do so after hours of trying and I
have bumped into a snag. Here is my server & client code.
**Server**
import java.net.*;
import java.io.*;
public class ServerFlash
{
public static void main(String[] args) throws IOException
{
ServerSocket serverSocket = null;
Socket connection = new Socket();
InputStream in = null;
boolean listening = true;
try
{
serverSocket = new ServerSocket(14804);
System.err.println("The server is now bound to port.");
}
catch (IOException e)
{
System.err.println("Could not bind server to port.");
System.exit(-1);
}
while (listening)
{
connection = serverSocket.accept();
if(connection!=null)
{
System.err.println("Connection to client has been
established.");
in = connection.getInputStream();
listening = false;
}
}
while (!listening)
{
int data = in.read();
if(data!=-1)
{
System.err.println(data);
}
}
}
}
**Client**
var server = new Socket();
server.connect("[insertmyip]",14804);
server.addEventListener(Event.CONNECT, onConnect);
server.addEventListener(Event.CLOSE, onClose);
server.addEventListener(IOErrorEvent.IO_ERROR, onError);
server.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
server.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
function onConnect(e:Event)
{
trace("Connection Established.");
}
function onClose(e:Event)
{
trace("Socket has been Close.");
}
function onError(e:Event)
{
trace("An Error has occured." + e);
}
function onResponse(e:Event)
{
trace("Responce has been recieved.");
}
function onSecError(e:Event)
{
trace("A SecError has occured.");
}
When I launch the server everything is okay. However when I launch the
client, it successfully connects to the server, but all of a sudden the
server receives data from the client (if you read the code the server
reads incoming data and displays it) and displays around 15 lines of code
and it does not accept any new data from the client. HOWEVER this only
happens when the client is launched from a website (or a folder) BUT it
works normally when I open the client as a test in Adobe Flash Pro.
If you require files and hand them over.
No comments:
Post a Comment