Jump to content
  • Advertisement

DollaMenunaire

Member
  • Content Count

    8
  • Joined

  • Last visited

Community Reputation

111 Neutral

About DollaMenunaire

  • Rank
    Newbie

Personal Information

  • Interests
    |programmer|
  1. This did it, thanks a lot for the help.    It's still a bit rough so I'll still have to clean up the connect/disconnect cases but the problem is absolutely gone.   I'll post back if I have any other questions but I think I'm good for now.   Thanks everyone else who pitched in as well.
  2. Interesting. I have been testing with 4 devices, ranging from 5 years old to 1 year old. They've at least been consistent in having this problem, which is a good thing of sorts.     Will do and I'll report back tonight if I figure it out, thanks.
  3. Sorry about double post, as well as the delay. Wanted to double check some other things prior to responding.    Here is the code. I removed as much outside code to keep this brief and I also wanted to confirm that the outside code was not impacting anything.    Server: import java.io.*; import java.net.*; public class GameMasterServer{ static final int HOSTPORT = 4321; int cnt = 0; public GameMasterServer() { OrderServer os = new OrderServer(); os.start(); } public class OrderServer extends Thread{ ServerSocket providerSocket; Socket connection = null; BufferedReader inCommand; BufferedWriter outCommand; String message; boolean masterServer; public OrderServer() { masterServer = true; } public OrderServer(Socket s) { connection = s; masterServer = false; } @Override public void run() { try{ if (masterServer) { providerSocket = new ServerSocket(HOSTPORT); OrderServer ls; while (true) { ls = new OrderServer(providerSocket.accept()); ls.start(); } } else { String line; inCommand = new BufferedReader(new InputStreamReader(connection.getInputStream())); if((line = inCommand.readLine())!=null) { outCommand = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream())); outCommand.write(line.trim() + System.getProperty("line.separator")); outCommand.flush(); outCommand.close(); System.out.println(line.trim() + " " + ++cnt); } } } catch (SocketException ex) {System.out.println("SOCKET EXCEPTION");} catch (IOException ex) {System.out.println("IOEXCEPTION");} finally { try { if (providerSocket != null) providerSocket.close(); } catch (Exception ex) {System.out.println("SOCKET NULL ERROR");} } } } } Client: Thread updateThread = new Thread() { @Override public void run() { while(runThreads){ try { sendMessage("Hello Doctor"); } catch (SocketTimeoutException se) {System.out.println("SSDEBUG : DROPPED PACKET");} catch (Exception e) { System.out.println("SSDEBUG : COMM ERROR"); e.printStackTrace(); } } } }; private String sendMessage(String msg) throws IOException { BufferedWriter outCommand; BufferedReader inCommand; String response; Socket hostConnection = new Socket(); System.out.println("1"); hostConnection.connect(new InetSocketAddress(StaticVariables.HOSTIP, StaticVariables.HOSTPORT),100); outCommand = new BufferedWriter(new OutputStreamWriter(hostConnection.getOutputStream())); inCommand = new BufferedReader(new InputStreamReader(hostConnection.getInputStream())); outCommand.write(msg + System.getProperty("line.separator")); System.out.println("2"); outCommand.flush(); messagesentcount++; response = inCommand.readLine(); System.out.println("3"); outCommand.close(); inCommand.close(); hostConnection.close(); System.out.println("4"); return response; } The problem occurs on the hostConnection.connect. It will hang there (it doesn't now because I attempted a timeout, now it will just timeout constantly for a 15 second span.   To reiterate, the client is on Wi-fi and this problem does not occur whatsoever when using localhost. 
  4. I am, at least for now, going to assume wi-fi will always be used. All of my testing has been done with wi-fi. The couple times I tried it without using wi-fi, the response times were steadily 200+ ms.      I tried going directly to the IP, same issue occurred. I have no problem showing the code, I will post it later tonight. 
  5. Upon further review, I actually am using TCP. My understanding of what TCP was not correct.    I suppose I'll have to make the switch.
  6.   I'll check wireshark if not tonight tomorrow. But the 2nd part of your post describes how the messages are actually sent back and forth, I think I didn't describe it too well. 
  7. I'm using UDP. It does receive the packets 'eventually' when going through the host, it just takes a longg time (30+ seconds at its worst)
  8. Hi guys and gals. I'll try and keep this as concise as possible while giving all the necessary details. This is regarding a game but I believe that this isn't necessarily a 'game' issue.   So I'm essentially making an Android game which communicates to a server (which is now my computer). The app will continuously request for updates from the server, and the server will collect the current game status and send it back to the client.    So, I got everything working while using a local ip. Then I investigated how to make a server out of my computer (This part I am very new to). So I used noip.com to set up a host dns, and set port forwarding on my router to send all data going to the port to my PC.    So now it's at the point where the android devices communicate to my PC through the hostname. However, after about a minute or so, the android device will send a message, but it will take 1-2 seconds for the server to see it. Then shortly after this begins, the connection will hang for 15-20 seconds at a time.    Things I've ruled out so far:   1) I've tried using my outside ip to send the messages instead of the hostname, same problem. 2) Doing a speedtest, I have 30 mb down and 6 mb up, so I think that's ok. These messages are presumably much smaller than other games (50 bytes back and forth) and I do a good amount of online gaming with no issue. 3) ping testing the hostname for an hour and the highest ping time was 2ms, which is much less than what I'm seeing.  4) I did confirm that neither side is hanging up, the android device is sending the message and then waits for the return, and the server is still waiting to see the message.  5) Switching back to localhost and I don't have this lag issue whatsoever. 6) I did some research on windows firewalls to confirm as best I can it's not interfering.    I'll gladly share any code/network information I can provide, but I'm not sure what would be beneficial right now, given the clues I have.    My next test will be testing this on a raspberry pi, but that will wait until tomorrow.    Thanks.  :D
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!