Sign in to follow this  
Followers 0
layer

TCP HTML Server

42 posts in this topic

Grr... This is o embarassing, but I want to know... Can I make an online server that will be like my webpage host that can be viewed over the internet not just from my harddrive? Like a dedicated server, that will host a simple HTML page... If you play Half life or any other mods, you usually download Steam, and Steam has it's on dedicated server for it's own games... But I don't need this for games :evil: I just want to make my own server that can display my own webpage... Or do I have to register a domain and pay?

Thanks... :)

PS,

I know I can use all those free sites like www.freewebs.com (which is what I always use, great service) but I just wanna try something new :D Thanks


FootbaG

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes. Have a look at the Apache HTTP Server Project.

There's a lot of configuration to it, but it will allow you to host a server on your computer for free.

You'll have to give people your IP address though (which will change from time to time most likely) whenever they want to access your site, or get a program like No-IP so that you can have a virtual domain.

I used No-IP's service to net me http://rks.no-ip.com (RKS are my initials). I have more than a virtual domain though, as my ISP doesn't allow connections on port 80 (default http) so I have http://rks.no-ip.com redirect to my IP address on port 8008 (currently http://207.81.202.138:8008), which then redirects to http://rksa.no-ip.com:8008 (looks nicer in the address bar).

Edited by Saunders

Share this post


Link to post
Share on other sites

I'm intersted in that too!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Ok, but can this be done within AutoIt? If not, I'll use the other thingy. And the no-ip looks cool. But how did you get your site up Saunders? Did you use that tool you linked me to?

Thanks again :)


FootbaG

Share this post


Link to post
Share on other sites

Oh, with AutoIt?? I suppose it could be done, but as good as AutoIt is at some things, an http server it was not designed to be. Someone here on the boards actually setup an http server with it a little while ago, but he couldn't even get it to show images (binary transfer required I guess, which Larry only recently got working, and slowly).

And my server is Apache, yes.

Share this post


Link to post
Share on other sites

Ok, but can this be done within AutoIt? If not, I'll use the other thingy. And the no-ip looks cool. But how did you get your site up Saunders? Did you use that tool you linked me to?

Thanks again :)

<{POST_SNAPBACK}>

Sure, AutoIt CAN do it, but you're talking about implementing the entire HTML protocol and server, and doing it in a script language. It would take a lot of time and debugging, and would probably be a major security risk. And very slow on top of all that (AutoIt is, after all, a scripting language). Why not just go with something tried and true?

Just my $0.02, take it as you will...

Share this post


Link to post
Share on other sites

Well as I said, I'm only experimenting with things... I'd like to see an HTML dedicated server in AutoIt, but I have no clue where to start. Any reference sites?

Thanks again...


FootbaG

Share this post


Link to post
Share on other sites

start with a program that can listen on a port, and create a socket and communicate in ASCII. Then read up on the HTTP protocol syntax, and make your program respond appropriately.

Good luck!

Share this post


Link to post
Share on other sites

Not sure what the HTTP protocol syntax is, but I googled it, and didn't really get much... Like, what exactly is it, but the rest, like listening on prot, comminication in ASCII is something I know about...

Again, thanks for the useful info :)


FootbaG

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

HTTP is an application-layer protocol, so if you already know the first 6 layers, then dive into the HTTP - Start with RFC 2616:

ftp://ftp.isi.edu/in-notes/rfc2616.txt

go from there...

Edit:Saunders beat me to it. Use his page, it's prettier! :)

Edited by blindwig

Share this post


Link to post
Share on other sites

Forgive me for asking so many things... I'm willing to take my time on all this, just to learn some, but, I briefly looked over some of it, and I just saw like, descriptions. Like how am I acutally supposed to apply my knowledge of HTTP to make a dedicated server. From skimming over some things, it was just, text, it didn't show what or how to do things. If I were to read that and not know what it's on, I would have no idea it was gonna help me make a dedicated HTML server. So will I actually get info out of this site provided that will help me make my program, or you know, will I not? It looks to blah. Maybe it's not my thing :)


FootbaG

Share this post


Link to post
Share on other sites

Forgive me for asking so many things... I'm willing to take my time on all this, just to learn some, but, I briefly looked over some of it, and I just saw like, descriptions. Like how am I acutally supposed to apply my knowledge of HTTP to make a dedicated server. From skimming over some things, it was just, text, it didn't show what or how to do things. If I were to read that and not know what it's on, I would have no idea it was gonna help me make a dedicated HTML server. So will I actually get info out of this site provided that will help me make my program, or you know, will I not? It looks to blah. Maybe it's not my thing :)

<{POST_SNAPBACK}>

Well, let's review your knowledge level, and I think we can help you from:

You say you have done an ASCII chat program. So am I correct to assume that you have 2 computers, each running your script, and when you type characters on the keyboard of one computer, they appear on the monitor of the other computer, and vise-verca?

You say you have knowledge of HTTP. So am I correct to assume that you know how to telnet into a server on port 80 and manually retrieve pages?

Share this post


Link to post
Share on other sites

I can make an ASCII chat program, actually, I've made one in C++ but never finished it because I don't know how to multi-thread (yet)... But I've done so much research on WinSock and stuff, looked at so many things, I can make one easily now...

HTTP? No knowledge... Telenet, I've tried using it before, I think I could use it simply, but I've never tried retriving pages.

Thanks :)


FootbaG

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

OK, lets start from the beginning with an ASCII chat program:

Make a gui window, put a big multi-line edit box on it (this will be the receive log) and then a single line editbox and a button at the bottom (these will be the send-text and send-button, respectively).

Make it so when you start the script, the script will listen on port 80 and establish a connection when requested. While connected, any data received will be concatenated into the editbox.

Once you think your program works:

run "TELNET 127.0.0.1 80" and it should connect. Anything you type will appear in the editbox on your script.

Once that is working:

make it so that when you type text in the 2nd editbox and click the button, that text is sent through the connection. This text should appear in the telnet window, if it is working right.

When the script loses it's connection, it should go back to listening on port 80, and repeat the cycle.

Once you get all that working, I'll tell you the next step.

Edited by blindwig

Share this post


Link to post
Share on other sites

I can make an ASCII chat program, actually, I've made one in C++ but never finished it because I don't know how to multi-thread (yet)...

This right here shows me that you are nowhere even close to being worried about writing an HTTP server. Writing a non-blocking single-threaded chat client is a trivial exercise. It can be done in less than 100 lines of code.

My suggestion to you is to forget about the RFC for the HTTP protocol and go towards something you might actually be able to follow: Beej's Guide to Network Programming.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Valik, I know.

Ok, this is greatly based off Larrys TCP server example... Because that's the only way I'd write a server...:

#include <GUIConstants.au3>
$the = GUICreate("Chat Server -- Not Connected " & @IpAddress1, 500)
Global $csock = -1
Global $rsock = -1
$recvd = GUICtrlCreateEdit("", 50, 5, 400, 300, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
$send = GUICtrlCreateButton("Send", 50, 320, 40, 20, $BS_DEFPUSHBUTTON)
$stuff = GUICtrlCreateInput("", 100, 320, 300, 20)
GUISetState()
TCPStartup ()
$sock = TCPListen (@ipAddress1, 80)
If $sock = -1 Then Exit
While 1
   $get = GUIGetMsg()
   If $get = -3 Then Exit
   If $get = $send Then
      If $csock > - 1 Then
         $ret = TCPSend ($csock, GUICtrlRead($stuff))
         If @error Then
            TCPCloseSocket ($csock)
            $csock = -1
         ElseIf $ret > 0 Then
            GUICtrlSetData($recvd, GUICtrlRead($stuff) & @CRLF, 1)
            GUICtrlSetData($stuff, "", "")
         EndIf
      EndIf
   EndIf
   If $rsock > 0 Then
      $ret1 = TCPRecv ($rsock, 500)
      If Not @error Then
         TCPCloseSocket ($rsock)
         $rsock = -1
      EndIf
   EndIf
   If $csock = -1 Then
      $csock = TCPAccept ($sock)
      If $csock >= 0 Then
         WinSetTitle($the, "", "Connected")
      EndIf
   Else
      $rsock = TCPAccept ($sock)
      $ret1 = TCPRecv ($csock, 500)
      If $ret1 <> "" Then
         GUICtrlSetData($recvd, "::" & $ret1 & @CRLF, 1)
         $spliti = StringSplit(FileRead("index.html", FileGetSize("index.html")), @CR or @LF or @CRLF)
         If $spliti[0] = 1 Then
             TCPSend($csock, $spliti[1] & @CRLF)
             GUICtrlSetData($recvd, $spliti[1] & @CRLF, 1)
         Else
             For $n = 1 to $spliti[0]
                 TCPSend($csock, $spliti[$n] & @CRLF)
                 GUICtrlSetData($recvd, $spliti[$n] & @CRLF, 1)
             Next
         EndIf
         TCPCloseSocket($csock)
      ElseIf @error Then
         WinSetTitle($the, "", "Not Connected -- " & @IpAddress1)
         TCPCloseSocket ($csock)
         $csock = -1
      EndIf
  EndIf
WEnd

Func OnAutoItExit()
   TCPCloseSocket ($csock)
   TCPCloseSocket ($sock)
   TCPShutDown ()
   GUIDelete($the)
EndFunc;==>OnAutoItExit

I did the telnet thing, and it works... Step 2?

BTW,

@Everyone who replied,

I greatly appreciate all the help, tips and advice :evil: Especially blindwig....

Thanks :D

EDIT: Updated code a little... Made it so you don't have to shutdown the server to display it, it just closes the socket and then reopens it when someone connects :D:)

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

OK, next, a command parser. For now, we'll use a debugging stub:

Func ParseInput($sInput)
    MsgBox(0,'Input Received', $sInput, 1)
EndFunc

Now, let me point out a problem in your code:

GUICtrlSetData($recvd, "::" & $ret1 & @CRLF, 1)

This is what you do everytime you receive any data - you assume that it is a full line of data, and you add a CRLF. What you need to do is this:

Create a buffer (an empty string)

Everytime you receive data, concatenate that data onto the buffer, up the point where a CR or LF character is (if any)

if there is a CR or LF character, trim the first part of the string up to that character and send that sub-string to the ParseInput() function. Put the rest of the string back into the buffer, and check for another CR or LF character. When there are no more CR or LF characters, go back to waiting for data (this should have been a tight loop, using StringInStr, StringLeft, StringTrimLeft)

The reasoning for this:

First of all, you can't assume that a packet will be a full line. You'll notice that when you type in telnet, each letter comes on a different line.

You'll never know how a packet coomes in, so you have to check them yourself. For example, if you sent data like this:

This is line #1

This is line #2

You would assume that it would come in 2 neat packets, but it might come all together in 1 packet, or come in 3 packets like this:

This is li

ne #1(CRLF)This i

s line #2

So you need to be able to handle that.

OK, once you get that working:

start your script

start your web browser, go to 127.0.0.1 for the address

notice the command that pop up in your virtual parser.

Read the HTTP RFC, learn these commands and how to respond to them (this is the big long hard part) and then you'll have an HTTP server!

I'd suggest to start with the GET command, and then go from there.

Share this post


Link to post
Share on other sites

omg, you're right! I'll have to take a bigger look into this in the morning... But I just created a webpage that said "test" in it :D Thank you soo soo soo soo soo much! For all your help, and everyone else too :) If I find another problem, I'll post back :evil: But I gotta go to bed now... Damn...

Thanks :D:mad:


FootbaG

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Hi, it's me again... Umm... I've started reading this manual thing for HTTP... And I've read some on the GET command, but it doesn't tell me how to respond to it, the only way I got the page to say "test" was to exit out of the server and then the page would finish loading. I think that's because I didn't respond to the commands, but I have no idea how, because I can't find any 'instruction' type things... Like when I get this from me trying to go to 127.0.0.1:

GET / HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*

Accept-Language: en-us

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

Host: 127.0.0.1

Connection: Keep-Alive

Do I actually have to type something back? Once I know what to respond back I can automate it pretty easily... I just need a kick in the butt I guess.

Thanks, again... :evil:

EDIT: Oh yea, one more thing... Are the TCP commands only supposed to work on a network or something? Because I ran my server script up above and was online with my cousin. I told him to run telnet [MYIP] 80 and he did, and it didn't connect to my server... So am I able to use these TCP commands on my computer and be able to actually chat with my cousin at his house?

Thanks.. :)

Edited by layer

FootbaG

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