No, what I wanna do is make a java XMLSocket server.
I followed this tutorial http://www.gotoandplay.it/_articles/2003/12/xmlSocket.php but it only shows you how to send and recieve text but I want to send and recieve the _x and _y of every player.
Heres the code in the tutorial:
import java.io.*;
import java.net.*;
public class simpleServer
{
public static void main(String args[])
{
// Message terminator
char EOF = (char)0x00;
try
{
// create a serverSocket connection on port 9999
ServerSocket s = new ServerSocket(9999);
System.out.println("Server started. Waiting for connections...");
// wait for incoming connections
Socket incoming = s.accept();
BufferedReader data_in = new BufferedReader(
new InputStreamReader(incoming.getInputStream()));
PrintWriter data_out = new PrintWriter(incoming.getOutputStream());
data_out.println("Welcome! type EXIT to quit." + EOF);
data_out.flush();
boolean quit = false;
// Waits for the EXIT command
while (!quit)
{
String msg = data_in.readLine();
if (msg == null) quit = true;
if (!msg.trim().equals("EXIT"))
{
data_out.println("You sayed: <b>"+msg.trim()+"</b>"+EOF);
data_out.flush();
}
else
{
quit = true;
}
}
}
catch (Exception e)
{
System.out.println("Connection lost");
}
}
}
Thanks for any help.
Look like this is code of simple Echo-like server. There is nothing about game or coordinates of any kind. All you can do is send to server string like: "x?" and recive answer like "x=100". Is this a game? :)
Well, code should be followed:
import java.io.*;
import java.net.*;
public class simpleServer
{
public static void main( String[] args )
{
// Message terminator
char EOF = ( char )0x00;
try
{
// create a serverSocket connection on port 9999
ServerSocket s = new ServerSocket( 9999 );
System.out.println( "Server started. Waiting for connections..." );
// wait for incoming connections
int x = 100, y = 100;
while( true )
{
Socket incoming = s.accept( );
BufferedReader data_in = new BufferedReader(
new InputStreamReader(incoming.getInputStream( ) )
);
PrintWriter data_out = new PrintWriter(incoming.getOutputStream());
data_out.println( "Welcome! type EXIT to quit." + EOF );
data_out.flush( );
boolean quit = false;
// Waits for the EXIT command
while( !quit )
{
String msg = data_in.readLine();
if( null == msg)
quit = true;
if( msg.trim( ).equals( "X?" ) )
{
data_out.println( "X = " + x + EOF );
data_out.flush( );
}
else
if( msg.trim( ).equals( "Y?" ) )
{
data_out.println( "Y = " + y +EOF );
data_out.flush( );
}
else
if( msg.trim( ).equals( "X+" ) )
{
x++;
data_out.println( "X increased" + EOF );
data_out.flush( );
}
else
if( msg.trim( ).equals( "Y+" ) )
{
y++;
data_out.println( "Y increased" + EOF );
data_out.flush( );
}
else
if( msg.trim( ).equals( "X-" ) )
{
x--;
data_out.println( "X decreased" + EOF );
data_out.flush( );
}
else
if( msg.trim ().equals( "Y-" ) )
{
y--;
data_out.println( "Y decreased" + EOF );
data_out.flush( );
}
else
if( msg.trim( ).equals( "EXIT" ) )
{
data_out.println( "Bye!" + EOF );
data_out.flush( );
quit = true;
}
else
{
data_out.println( "You sayed: <b>" + msg.trim( ) + "</b>" + EOF );
data_out.flush( );
}
}
incoming.close( );
}
}
catch( Exception e )
{
System.out.println( "Connection lost, shutting down..." );
}
}
}