Creating a server
Monkey Forums/Monkey Beginners/Creating a server| 
 | ||
| I want to create a server and clients to talk with the server. So I went to: http://www.monkeycoder.co.nz/docs/html/Modules_brl.tcpstream_TcpStream.html and ran this example at there: 
#If TARGET<>"glfw" And TARGET<>"android" And TARGET<>"ios" And TARGET<>"stdcpp"
#Error "Invalid target!"
#Endif
Import brl.tcpstream
Function Main()
    Local stream:=New TcpStream
    
    If Not stream.Connect( "www.monkeycoder.co.nz",80 )
        Print "Failed to connect!"
        Return
    Endif
    
    Print "Connected!"
    
    stream.WriteLine "GET / HTTP/1.0"
    stream.WriteLine "Host: www.monkeycoder.co.nz"
    stream.WriteLine ""
    
    While Not stream.Eof()
        Local line:=stream.ReadLine()
        Print line
    Wend
    
    stream.Close
    
    Print "BYE!!!!"
End
it's working fine. Then I installed xamp with apache and created a page in html who's printing "hello World" at http://127.0.0.1/test.html and works fine. but I tried to replace If Not stream.Connect( "www.monkeycoder.co.nz",80 ) to If Not stream.Connect( "http://127.0.0.1/test.html",80 ) And replaces stream.WriteLine "Host: www.monkeycoder.co.nz" to stream.WriteLine "Host: http://127.0.0.1/test.html" and when I run the program, it's printing "Failed to connect!" What am I doing wrong? | 
| 
 | ||
| Oh, you have corrected message! yiotoo wrote:  If Not stream.Connect( "http://127.0.0.1/test.html",80 )  Change to If Not stream.Connect( "127.0.0.1",80 ) stream.WriteLine "Host: http://127.0.0.1/test.html" to Host: 127.0.0.1 App has to connect to server then send some extra info to server to request a web page according HTTP protocol. Host, Get, Post, etc commands. Wait answer and close connection. | 
| 
 | ||
| Worked!!!  ty!! | 
| 
 | ||
| No http:// and test.html are in the .connect() method and "Host" command. Call html document in the GET command, where GET / means return default document (usually index.html, etc) |