Sign in to follow this  
Followers 0
dinodod

TCP Listen not working?

10 posts in this topic

I am trying to simply open a TCP connection to googes web site and then be able to pull the html code back down to pass to my client. But after trying to pull out my hair over this, I am still stumped over why on earth I can't listen for data!

It appears that I am able to actually connect to google's web site but then why can't I get the data back from the web site??

I tried using just the TCPRECV command but it was not returning any data!

;SERVER!! Start Me First !!!!!!!!!!!!!!!
#include <GUIConstants.au3>

; Start The TCP Services
;==============================================
TCPStartUp()

Dim $URL = "www.google.com"
Dim $IP = TCPNameToIP($URL)
Dim $PORT = 80
Local $MaxLength = 2048; Maximum Length Of Text

_CreateDebugWindow()
_SetDebugInfo(" URL: " & @TAB & @TAB & @TAB &$URL)
_SetDebugInfo(" IP: " & @TAB & @TAB & @TAB &$IP)

$socket = TCPConnect ($IP, $PORT)
_SetDebugInfo("TCP Connect?  -1 is bad" & @tab & $socket)

$MainSocket = TCPListen($IP, $PORT)
_SetDebugInfo("TCP listen?  -1 is bad" & @tab & $MainSocket & @TAB & @error)

sleep(5000)
;While 1
;   $Data = TCPRecv($socket, $MaxLength)
;WEnd

_SetDebugInfo("TCP receive finished")

;sleep(4000)
TCPShutdown()




Func _CreateDebugWindow()
    ; Create Debug window
    ;==============================================
        Dim $GOOEY = GUICreate("Debug Window",300,200)
        Global $edit = GUICtrlCreateEdit("",10,10,280,180)
        GUISetState()
EndFunc

Func _SetDebugInfo($Text)
    GUICtrlSetData($edit, GUICtrlRead($edit) & $Text & @CRLF)
EndFunc
; ================================================================================================

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You should have posted this into the "General Help and Support" section.

BTW, Google frontends has been done many times here : the Search button is your friend (Google too :))

You don't need the TCPListen(), but you should send something to the connected socket.

An HTTP request should be a good idea.

Edited by Apzo

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You'll need to use the HTTP protocol. Send an HTTP request before to make google respond. For example:

GET /forum/index.php HTTP/1.1

Host: www.autoitscript.com

Connection: close

User-Agent: My Browser (AutoIt)

Accept: text/xml,text/html,text/plain,image/png,image/jpeg,image/gif

Accept-Charset: ISO-8859-1,utf-8

Keep-Alive: 300

See: ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt

Edited by TomZ

Share this post


Link to post
Share on other sites

You should have posted this into the "General Help and Support" section.

BTW, Google frontends has been done many times here : the Search button is your friend (Google too :party:)

You don't need the TCPListen(), but you should send something to the connected socket.

An HTTP request should be a good idea.

:) UH Dear. your right about posting in the correct forum. That's my bad. Feel free to move it if you need to. And yes, :) I was searching for some keywords in Autoit for some examples. Problem is, all I was fining was TCP Server / Client scripts and then I came across one TCP MADE EASY posting but it wasn't so easy :lmao:

But I will look for GOOGLE scripts instead, perhaps that will point me in the correct direction. As for the HTTP Request suggestion, I looked at the AUTOIT Help file & the _IE Funcs but was not finding anything. I'll look a bit more and see if I can find something in the meantime. I'll need to learn how to format a HTTP Request and send it.


Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites

You'll need to use the HTTP protocol. Send an HTTP request before to make google respond. For example:

GET /forum/index.php HTTP/1.1

Host: www.autoitscript.com

Connection: close

User-Agent: My Browser (AutoIt)

Accept: text/xml,text/html,text/plain,image/png,image/jpeg,image/gif

Accept-Charset: ISO-8859-1,utf-8

Keep-Alive: 300

See: ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt

Thanks for the link but HOLY COW, I won't be reading all of that!!! :) I will look into the http request and try to find some examples in this site.

Thanks!


Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I looked for the search words 'google' and 'http request' in this site then looked at the 1st 23 pages in the example scripts but alas, I am still not seeing anything that will assist me. I am about to go to work now but I'll be back on around Midnight EST. If anyone could perhaps give me a little nudge to a sample, I wuld be ever so happy :)

THX!

UPDATE:

http://web-sniffer.net/?url=www.google.com...e=GET&uak=0

HTTP Request Header

Connect to 209.85.137.99 on port 80 ... ok

GET / HTTP/1.1[CRLF]

Host: www.google.com[CRLF]

Connection: close[CRLF]

User-Agent: Web-sniffer/1.0.27 (+http://web-sniffer.net/)[CRLF]

Accept-Encoding: gzip[CRLF]

Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]

Cache-Control: no[CRLF]

Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]

Referer: http://web-sniffer.net/[CRLF]

ok, if I understand this, I need to TCPSend each line since this is my header?? Then what??? Am I even on the right track??

Thanks!

Edited by dinodod

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites

ok, if I understand this, I need to TCPSend each line since this is my header?? Then what??? Am I even on the right track??

I think it's better for you to use InetGet() or _INetGetSource(). Otherwise I'll recommend: TCP/IP Illustrated

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I agree with /dev/null. You should just use _INetGetSource. It would be much easier, and most-likely, more efficient. However, if you would still like to do it your way, then I recommend reading this HTTP tutorial.

http://www.jmarshall.com/easy/http/

Edited by cppman

Share this post


Link to post
Share on other sites

Thanks to both your answers. What I am trying to design is a Internet Filter / Proxie application. I'm not sure if _INetGetSource is the correct solution for what I need as I would need to be able to handle every type of internet requets (Secure pages, form completions, file downloads, etc) but I will give it a shot. Heck, it's a good start as any at this time :)

Thanks for the help guys, I'm sure I'll have more issues arising soon enough :)


Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites

Thanks to both your answers. What I am trying to design is a Internet Filter / Proxie application. I'm not sure if _INetGetSource is the correct solution for what I need as I would need to be able to handle every type of internet requets (Secure pages, form completions, file downloads, etc) but I will give it a shot. Heck, it's a good start as any at this time :)

Thanks for the help guys, I'm sure I'll have more issues arising soon enough :)

Internet Filter/Proxy? Secure pages, form completion, file downloads? Do you know, it takes some 100 man years to develop such a thing from scratch?

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0