Adam1213 Posted May 25, 2007 Share Posted May 25, 2007 I run a server on port 80, but I dont want to open port 80 to the web or run my server locally on 81, so I wrote this program, it works by: Getting the request from the client Sending the request to the server Getting the servers response Sending the servers response to the client expandcollapse popup$port=81 ; remote TCPStartup() $mainsocket= TCPListen('', $port, 100) ; I know it probably should be @ipaddress1, however localhost + 127.0.0.1 did not work until i made it blank (before my ip worked, and it still does) If $mainsocket = -1 Then $err = @error MsgBox(16, "Error", "Unable to connect." & @CRLF & @CRLF & "dec: " & $err & @CRLF & "hex: 0x" & Hex($err, 8)) EndIf While 1 $socket = TCPAccept($mainsocket); If $socket >= 0 Then $recv = TCPRecv($socket, 1000000) ;_________________ SERVER ______________________________ $server_con=TCPConnect (@IPADDRESS1, 80) if $server_con=0 OR @ERROR then msgbox(0,'Error','could not connect to local sever') exit endif TCPSend($server_con,$recv) $server_recv='' $i=0 $newrecv=1 while ($server_recv='' OR $newrecv=1) AND $i<1000 $i=$i+1 $len=stringlen($server_recv) $server_recv&=TCPRecv($server_con, 10000000) if StringLen($server_recv)>$len then $newrecv=1 else $newrecv=0 endif sleep(10) wend TCPSend($socket, $server_recv) TCPCloseSocket($server_con) ;_______________________________________________ TCPCloseSocket($socket) endif sleep(100) wend My web server was taking ages to do ajax autocomplete, and now its instant through this, dont know why but it works!. IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now