![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 284
Rep Power: 4
![]() |
Re: online game
BinarySurfer, I have followed your suggestions but it just hangs now. I added those methods to the Server class and i assume that the ServerThread class isn't even used anymore right and that the client stays the same?
Here is the code i have after making those changes. Server class java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
|
|
|
|
|
|
#12 |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
@Freaky Chris
I've never done it that way. A better way might be to make the socket public or the send method public. Then, in the other applications, you can call the class that has the connection and use the connection or call the send class. java Syntax (Toggle Plain Text)
@cwl157 Sorry, I only got to send you the sever class, but the server looks right. The client does have to be redesigned. Not implementing what you need, here's the bare bones of the client java Syntax (Toggle Plain Text)
Last edited by BinarySurfer; Apr 19th, 2008 at 9:52 AM. Reason: Forgot to inicialize 2 objects |
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 284
Rep Power: 4
![]() |
Re: online game
ok, so i changed the client and created a class that has the main method where i create a client but nothing happened. I would run the client and i never got any exceptions or messages it would just quit. I changed the sendData method to public and passed it a string but when i do that and run the client i get a nullPointerException. It occurs in the sendData method at the output.writeObject(data) line and in main at the line where i tell it to send the data. I'll post the client and server again.
Server java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
|
|
|
|
|
|
#14 |
|
Hobbyist Programmer
|
Re: online game
BinarySurfer, i thought about making the socket public but i was thinging about the fact that if multiple peopel connect to the server then you have the issue of all the connection sockets being named the same, which of course is not going to be helpful.
However creating a class would work well, cause it would allow you to store other information about that client as well which could prove helpful. Just then remains on knowiing which class you want to check for the connection. As i know if you use a couple of arrays then they can link niceley bassed of one thing such as a user name and from that you can then retrieive the IP from another array. But i guess you could implement something very similar with classes. Cheers, Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#15 |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
Sorry, I think you go what I said to FreakyChris mixed in, but if you want to keep the client class separated from the game class, that's fine. In the newMain class, you have the idea down, but the problem is the Client class never attempted to established a connection with the server, which is why there is no error or output and it quits. Keeping it the way you have it, change the newMain as follows:
java Syntax (Toggle Plain Text)
Now the server and client should connect and communicate. Last edited by BinarySurfer; Apr 19th, 2008 at 1:20 PM. Reason: Needed more dots :P |
|
|
|
|
|
#16 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 284
Rep Power: 4
![]() |
Re: online game
I am really confused. It does print out to all the clients a string that i enter on the server. Now how do i make it so the client can send Strings to the server and then the Server print them on all clients? I think that is the next step. That way in my game I can have the person enter their move via keyboard input and then pass it to the server which would then print it out on all clients so both clients could see all the moves. Then when there is a winner I could send that to all clients and have it displayed as well. So basically I need a method that takes a string and sends it to the server and then the server passes it to all clients which would be max 2 clients because 2 people play at once. Here is the Server class's receive method that I have been working on but does not work. I thought if this could return what is received as a String then that String could be passed into the send method and sent to all the clients. I just hangs when receive is hit.
java Syntax (Toggle Plain Text)
Last edited by cwl157; Apr 19th, 2008 at 5:28 PM. |
|
|
|
|
|
#17 | |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
The server and client are connected and chatting?
Quote:
For sending data, for both the client and the server, why don't you use the send method? When ever you want to send data from either, you just call the method with the info as an argument. java Syntax (Toggle Plain Text)
|
|
|
|
|
|
|
#18 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 284
Rep Power: 4
![]() |
Re: online game
the receive method i posted does not work it just hangs waiting for something when its called. Also, I can just call the client's sendData method from the Server class? When i send data from the client to the server the Server never receives it. When i call sendData from the client the Server never gets it. So i thought i would need a receive method in the Server class. The send method of the Server sends the string just fine to the Client.
|
|
|
|
|
|
#19 |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
Time's getting a little tight here now that finals are around the corner, but post your client-server classes and I know this is a stupid question, but is your firewall blocking the connection? Your Windows firewall too?
|
|
|
|
|
|
#20 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 165
Rep Power: 2
![]() |
Re: online game
Thats not a stupid question, my Client-Server program was originally being blocked by a firewall as well.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |