Advertisement

How is a real-time server port "find" known to client code

Started by March 02, 2017 11:39 AM
51 comments, last by hplus0603 7 years, 8 months ago

On Windows, download putty. Set it up to connect using telnet protocol, to host 192.168.1.2, to port 52059. If the server is correctly running and listening on that address, it should see a connection when you open that window.

At the moment only trying to find out about using Putty and what its all about, and as I search, the question that pops to mind is - Can putty be used with windows 10?

I installed on W10, but from my preliminary observations it seems it only works well up to W7 or there is work around if W10 was upgraded from W7. Not so in my case

https://mediatemple.net/community/products/dv/204404604/using-ssh-in-putty-

https://social.technet.microsoft.com/Forums/en-US/0a3f62e4-fe5e-4926-a277-99588258bf62/windows-10-ssh-tunnel-with-putty?forum=win10itprogeneral

[damn! @[member='Khawk'], this narrow width design is really off-putting. A partial role-back will be great, please. EDIT only on chrome, but not Microsoft-Edge, maybe CSI forum thing]

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

You don't need SSH, and one of those links presumably omits Windows 10 because it was written before Windows 10 existed. The creator says it works fine on Windows 10 and I don't see why it wouldn't.

Regarding your more general problem, you will want to consider both ends of the equation here, since you control both server and client. Using Putty will tell you whether your server is reachable. Another approach is to change your client to contact a known server (e.g. gamedev.net, port 80), to see whether it is capable of making outside connections.

Advertisement

since you control both server and client. Using Putty will tell you whether your server is reachable.

Ok, i get the gist now. I was thinking something deeper before... :wub:

Using Putty, to server, it connected


IP 192.168.1.2  ***%% :52059
Waiting...
Accepted connection : Socket[addr=/192.168.1.2,port=[not sure if is sensitive..],localport=52059]

^

Now just tried simplified client code again, with all fire walls turn-off - still stuck at

sock = new Socket(serverIP, 52059)

with connectException ETIMEDOUT if within try-catch

Maybe a client code that has argument to increase allowed timeout is required (just a thought)

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

If the client and server are on the same network then there's almost zero chance that the default timeout is too short (although I did tell you exactly how to choose the timeout, over in the chatroom the other day).

Are you absolutely sure that the value of serverIP is correct?

Are you absolutely sure that the value of serverIP is correct?

this is hard-coded to top of the client code


private String serverIP = "192.168.1.2"; 

I know it deosn't get out scope because it's here


public class FSendfileActivity extends Activity {
    private Socket sock;
    private String serverIP = "192.168.1.2";
    ...
    ... 

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

If it was out of scope it wouldn't compile at all.

Are you sure you have the port number correct, then? You're logging both port and localport which suggests that you might be getting them mixed up. (In practice, you don't need to know the randomly generated port that is made for each connection.) The only port number you should care about is the single number you chose as your "well-known" port.

Also, change the code to ensure your timeout is at least 3 or 4 seconds, and see how it goes.

Advertisement

I would be more worried that the Android client is not on the same network as the server (or is not being routed to the server.)

Run the client code on the same machine as the server, and see how it goes.

Also, run Wireshark on the server, looking for packets on port 52059, and see what shows up when you start the client.

enum Bool { True, False, FileNotFound };

That's a good point, actually. The Android code could be connected to (a) the telecommunications provider network, (b) the home WiFi, or (c) the emulator context. In the first case, it can't connect to a locally hosted server at all. In the second case it should be okay. And in the 3rd case it seems to be a bit more complex, but is probably okay if it's not attempting to connect to localhost, if I remember correctly.

You're logging both port and localport which suggests that you might be getting them mixed up.

Is there a way to confirm I'm using a local port? I obtained that port number by first setting server code port number to '0',

so it generated a random local port number. I then fed that back as local port number. Is this a correct means of obtaining a local port number?

Also, change the code to ensure your timeout is at least 3 or 4 seconds, and see how it goes.

Ah, I don't know a code line that would let me do this, i even scrolled through to the advice you gave in the chatroom but still didn't get it because there is no construct in the client code and the client runs inside Android class not with Android class, so FSendfileActivity constructor wouldn't have api to change the client timeout

All I'm suggesting in this case is to take what you already have,

use a different constructor, then make the explicit connect call on the next line:
................
The timeout should at least let you get to the next line of logging, and confirm that the system is
at least trying the connection

I'm sure i'm missing something so 'would be glad if you could elaborate further

I would be more worried that the Android client is not on the same network as the server (or is not being routed to the server.)

Run the client code on the same machine as the server, and see how it goes.

Also, run Wireshark on the server, looking for packets on port 52059, and see what shows up when you start the client.

Ok i should run both in Java, I will try... wait if i'm running 2 Java programs at the same time, in the same IDE, never tried that before, but wouldn't there be an exception ,.... a crash?

Also , my novice-ness is laid bare again, because i never heard of Wireshark program before. But thats what googling is there for ...so i will take a moment to check this and see how to do this

That's a good point, actually. The Android code could be connected to (a) the telecommunications provider network, (b) the home WiFi, or (c) the emulator context. In the first case, it can't connect to a locally hosted server at all. In the second case it should be okay. And in the 3rd case it seems to be a bit more complex, but is probably okay if it's not attempting to connect to localhost, if I remember correctly.

There is zero network data on the phone so I can guarantee they are both on router wifi

Many thanks @Kylotan and @hplu0603

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

"Is this a correct means of obtaining a local port number?" - No, just pick one. Ideally above 1024. If it is already taken, you'll get an error or an exception. 52059 is probably fine, if you like that number. The server must listen using that port, and the client must connect using that port. At no point should any other port number enter the equation.

"I don't know a code line that would let me do this" - Step 1, construct an unconnected socket, Step 2, connect while setting the timeout. You'll need to create a SocketAddress from your hostname and destination port number to do that.

"running 2 Java programs at the same time, in the same IDE" - Are you running this Android program on your phone, or on an emulator? Each has different networking environments, and this information is critical.

This topic is closed to new replies.

Advertisement