This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes Networked programing code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Networked programing code" Watch "Networked programing code" New topic
Author

Networked programing code

Jeffrey Bowles
Greenhorn

Joined: Mar 01, 2009
Posts: 2
This code is to transfer the X and Y coords of the player to a different computer so i can make a networking adventure code but the networking method is static so i can send the X and Y coords from it. I have tried to remove the static from the method it does not work so i am posting it here. (this is only the server code it will not run proberly if you try and compile it on your comp i just need help how to get the X and Y coords into the networking method)




Any help on this would be great
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Welcome to JavaRanch.

The code is a bit confusing. This class is run as an applet on one or more clients, and as an application on the server?

I don't see any code in the applet that would make a network call to the server. You may want to start reading through the networking chapter of the Java Tutorial. It contains an example of how to create a client/server pair that communicates over sockets.

The server code has a lingering bug: Don't println to a Socket.


Ping & DNS - my free Android networking tools app
Jeffrey Bowles
Greenhorn

Joined: Mar 01, 2009
Posts: 2
The code itself works as it is now but if i try and take a variable say to transfer player positions i get a error of

"non static variable X cannot be referenced from a static context"

that is on line 98 that i get that error so how do i get rid of that error. The reason i want to this is so i can transfer a players position to another computer on a network running the client code. (which is basically the same) Then draw the player on the map so it can be a networked 2 player game. here is just that code again



The error comes at the line
pw.println("X:"+X );
The X is to transfer the X coords of the player

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Static code (like the main method) can't access instance variables, only static fields. But since X is set in the client -and not anywhere in the server code- what good does accessing it do?

I think the code would benefit from a strict separation of the client and the server in two different classes.

I'm also a bit sceptical about you saying that the code works - there's no networking code in the client, so how could it work?

(And you will need to tackle the issue discussed in the article I linked to - unless you can guarantee that both client and server will always run on Windows.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Networked programing code
 
Similar Threads
the display of my applet in html got problem~
How to add in button and paint in applet?
Improving Graphics.
Racing game does not work(HELP!!!!)
Parsing a text file to an arraylist