Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sockets -.-
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Donny




PostPosted: Sun Apr 17, 2011 5:35 pm   Post subject: Sockets -.-

trying to make an online game, but i'm having troubles.
I'm not very good at java i've been teaching myself for a few weeks now but this has got me stumped.
CODE:

public void communicate(int x2, int y2, int clientid) throws Exception{

  Socket clientSocket = new Socket("localhost", 6789);
  DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
  DataInputStream inFromServer = new DataInputStream(clientSocket.getInputStream());
                    clientid = inFromServer.readInt();
                    System.out.println(clientid);
                    outToServer.writeInt(x2);
                    outToServer.writeInt(y2);
                    x3 = inFromServer.readInt();
                    y3 = inFromServer.readInt();
                   System.out.println(x3);
                   System.out.println(y3);
                   
                   
                 
    }


I need to be able to access the x3 and y3 outside of the communicate void but it always returns the value as 0, when i put println with x3 outside it just prints 0, how can I make it do anything? i've tried making public int setX(){return this.x3} and such but it still won't work, any suggestions? (it does print the proper x and y values in the console just not when i try outside of the class)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Apr 17, 2011 5:56 pm   Post subject: RE:Sockets -.-

Could be a problem with scope. http://en.wikipedia.org/wiki/Scope_(programming) The code example does not show how/where x3/y3 are created.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Donny




PostPosted: Sun Apr 17, 2011 7:47 pm   Post subject: RE:Sockets -.-

It's in the variables part
CODE:

Class example extends Applet {
    public int x3, y3;
        public void init(){

     }

}
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: