Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
User | Post |
neotransotaku Posts: 801/1860 |
It is probably best to send objects that all derived from a base class. On the sender's end, they initialize a "packet" and send that off using an object writer. Then using a series of instanceof checks at the receiver's end, to determine the actual type of the "packet" that is sent so that the data can easily be extracted. |
Squash Monster Posts: 127/296 |
Sorry it took so long to get back to this thread.
Eventually we found the problem -- my friend typoed when he set up port forwarding so his router sent requests to connect to the game through the wrong computer . A new question arises: Currently, as you may have noticed, we're sending updates as strings and using number formatting functions to get them back together and stuff. I'm trying to come up with a better way to go about that. What would be the best way to format data? Make an Update class and send objects of it across through serialization? |
neotransotaku Posts: 617/1860 |
testing your code, everything is okay. You can leave the code intact because I didn't notice difference between SocketServer and Socket. So, SocketServer is in Server class and Socket is in Client class. That's correct.
I believe your problem goes down to IP address problems. On the computer that will run the server, get the IP address of the server using ipconfig (if you are using windows). If the ip address starts with 192 or 10, you need to get the IP address of the internet connection somehow. The exception to this is if both computers are on the same network. Then you can just stick with the 192 or 10 IP address. Once you get this IP address, then this is the IP address the client will use when you run the client on another computer. If you get the IP address not to start with 192 or 10, then the issue now is the server is behind a firewall and you need to poke a hole through the firewall to accept connections on the server's port number. |
Squash Monster Posts: 126/296 |
We're not on the same network, and we were using IP addresses.
The socket tutorial makes too many assumptions and doesn't work all that well. But yes, I did check my code against it. They're quite similar. How exactly would you recomend setting it up so they're not listening and connecting the same port number? Would you connect twice, and have each computer use one port to send and the other to receive? |
Zem Posts: 591/1097 |
The solution for the <pre> issue is to use CSS to have it hide <br> tags inside it. For example, in my profile, I have:
<style type="text/css">pre.nobrpre br { display: none }</style><pre class="nobrpre">blah blah blah</pre> |
neotransotaku Posts: 595/1860 |
Say, are you guys on the same network? if you and your friend are behind two NATs, then you two won't be able to see each other. As a result, you need the actual IP address of the connection, plus some port forwarding, to be able to connect properly.
The reason why you see 0.0.0.0 locally is because servers don't care where they are, just only what port number they need to listen to. Also, it is best not to be listening and connecting with the same port number. So, when you make a client socket, it shouldn't be the same socket as the server. EDIT: Here is Sun's Socket tutorial if you haven't looked at it yet--but I believe you did the same thing in the tutorial |
Squash Monster Posts: 125/296 |
A friend and I are trying to learn how to connect to eachother's computers via Java sockets, and aren't having very much luck.
Every time we try to run, the client side says it timed out, and the server side claims its IP is 0.0.0.0. Anyone have any ideas what could be going wrong? (Code follows. Sorry it's all double-spaced -- blame the pre tag. Anyone have a solution for that?)
|