I've been using Java for a few years now and, until now, I've always felt like I could overcome any obstacle in Java with a little Googling and some trial and error. Recently I decided to give Sockets a try after avoiding learning anything network-related for my entire programming career, but I don't think I can go any further on my own. To state it bluntly, I really have no idea how the internet works insofar as programming is concerned.
Currently all I want to do is to be able to send a message to a server across the internet, have the server process that message, and then have the server send messages back to multiple clients. I'm going to post bits and pieces of code rather than posting everything for now because, at this point, the issue is really just fundamentals. I also think it's important to explain what I hoped the code did. What I have written works fine when I run it locally, but that's probably expected. If nothing looks amiss here I will post the full thing, but like I said, I think the problem is just my understanding of the code rather than the code itself.
1. I create a server:
2. I then wait for and accept all clients attempting to connect to the server:
3. I obtain some sort of way to read messages from the client (a thread is started for each client by this point):
4. I read messages from the cilent and process them in some way:
5. I obtain some way to write message to the client:
6. I write a message to the client:
1. I connect to a server:
2. I obtain some way to write messages to the server:
3. I write a message to the server:
4. I obtain some sort of way to read messages from the server:
5. I read messages from the server and process them in some way:
When creating the Socket for the server in the client, the host I use is the IPv4 address I get when I run ipconfig. I used port 1982. I don't really know what either of those mean, but it worked in testing so I ran with it. I also obtain the same address when I run:
When I give that address to a friend across the country running the client, however, absolutely nothing works. I guess I sort of expected some wizardry to take over and for everything to work out fine by sharing a single IP address, but now I'm back at square one and hours and hours of Googling haven't lead me any closer to an answer. Any help would be appreciated.