New topic: TCPSocket changing port after connect?
<http://forums.realsoftware.com/viewtopic.php?t=46226> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message x11joex11 Post subject: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 7:33 pm Joined: Thu Oct 12, 2006 7:21 am Posts: 414 Location: California Hi guys, Weird thing happening to me. My code is below. FTPSocketClass just subclasses TCPSocket. //Make connection to the passive port. ftpPassiveSocket = new FtpSocketClass ftpPassiveSocket.Port = passivePort1 ftpPassiveSocket.Address = passiveHost ftpPassiveSocket.infoWin = new infoWindow() ftpPassiveSocket.Connect() MsgBox "Connecting To:"+ftpPassiveSocket.Address+":"+str(ftpPassiveSocket.Port) I'm working on a FTP app, but when I try to connect to a port other than 21, it fails to connect. If you know a lot about FTP you know it chooses random port ranges for it's passive FTP mode. So I have to make a connection to random ports on the server. So I did a msgbox command to see where it was trying to connect and for some reason it's always 65,300+ (seems to always increment by 1 or 2), when I know for a fact it's some lower numbers like 41 or 221 or something random it seems in that range. Is it because these are privileged ports that I am not allowed to even connect to an outside server? I can understand listening on my own server and having it change my port randomly, but connecting to an outside server I thought would not be an issue, but apparently it is? I'm very confused, any light on the matter would help. I don't claim to know what I'm doing with FTP either, I may be misunderstanding how passive mode vs. active mode setup works. _________________ Joe Astrahan CEO - iTechware Inc. iTechware - Internet, Technology & Software Google Adwords Campaign Management "Rocketing you to the top!" 10900 Los Alamitos Blvd, Suite #210 Los Alamitos, CA, 90720 (949)354-4ADS Top timhare Post subject: Re: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 7:50 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11881 Location: Portland, OR USA That sounds normal to me. When you connect to a service like that, it needs to keep its main port, port 21 in this case, available, so it switches you off to a random port in the range of "free" ports. That sounds consistent with what you're seeing. Is this causing a problem in your code? Top charonn0 Post subject: Re: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 8:19 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1043 Location: San Francisco, CA, USA The port you set (e.g. 21) is the remote port. After calling Connect() the Port property is changed to represent the local port that RS is using, not the remote port which you're connecting to. _________________ Boredom Software Top x11joex11 Post subject: Re: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 8:56 pm Joined: Thu Oct 12, 2006 7:21 am Posts: 414 Location: California It just makes it hard to verify that the socket is correctly binding to the right address on the other server, but I think I get what you guys are talking about now. I did a test of connecting on port 21, and noticed it changed the 'port' value as well, I suppose for connections with ports, there is the port you connect to on the server machine and a port for listening on your machine and they don't have to be the same apparently. I guess I didn't understand that until now. I'm trying to connect to one of the ports that my FTP server is telling me should be open for the passive connection but it just sits there and is never able to connect, so not sure what to do now. I already successfully logged into my FTP server sent username and password, got current directory, just getting this double socket setup seems to be difficult. For example, the FTP server responds: 227 Entering Passive Mode (64,13,232,147,206,183) The first 4 comma's are the IP Address, the other are 2 random ports it's supposed to have opened. I believe I should be able to connect to those, but I can't for some reason, not sure why. I set the correct host and port on a new tcpsocket but it justs hangs when trying to connect, not even any errors. EDIT: http://www.rhinosoft.com/respcode.asp?resp=227&prod=fv Apparently according to this I misunderstood what the port stuff meant. I guess I'm supposed to take the first port value on there multiply by 256 then add the second port and THAT is the port I'm supposed to connect to. Wish they made that clear in the documentation. Anyways going to test that out and let you know if it works. Essentially it's this. Quote:227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). The values of h1-h4 are the IP address the server is listening on. The values of p1-p2 are used to calculate the port the server is listening on using the following formula: PASV port = (p1 * 256) + p2. _________________ Joe Astrahan CEO - iTechware Inc. iTechware - Internet, Technology & Software Google Adwords Campaign Management "Rocketing you to the top!" 10900 Los Alamitos Blvd, Suite #210 Los Alamitos, CA, 90720 (949)354-4ADS Top x11joex11 Post subject: Re: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 9:05 pm Joined: Thu Oct 12, 2006 7:21 am Posts: 414 Location: California Sweet, now it works, I guess that was my problem was the calculating of the passive ports, that was really unintuitive! _________________ Joe Astrahan CEO - iTechware Inc. iTechware - Internet, Technology & Software Google Adwords Campaign Management "Rocketing you to the top!" 10900 Los Alamitos Blvd, Suite #210 Los Alamitos, CA, 90720 (949)354-4ADS Top charonn0 Post subject: Re: TCPSocket changing port after connect?Posted: Wed Dec 12, 2012 11:04 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1043 Location: San Francisco, CA, USA x11joex11 wrote:that was really unintuitive! You said it! That really tripped me up too. x11joex11 wrote:Wish they made that clear in the documentation. Here's the unofficial FTP docs I relied on when implementing my FTP client code. I found it most helpful. _________________ Boredom Software Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
