Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

question on browser to server connection

connection

  • Please log in to reply
2 replies to this topic

#1 tommytopple

tommytopple

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 14 February 2012 - 07:11 PM

Hello people. I am trying to develope a html link that when i click on ym web site will contact my c+ server. In this link i wish to tack on the end a variable like how people do it in php

heres an example

www.site.com/?variable

I know so far that if my server is running and i type local host into my web browser that it will make a connetion with my server. So the concept is working right. This will only work with my loopback address 127.0.0.1 and local host which are the same thing. If i try to use my ip address for this, it will not work. this is veyr annoying and i dont understand why if my loopback address works why wont my ip. I need to be able to use my ip to finish this concept to fully work.

Ive come to a few conclusions. Either it is a port forwarding problem or i need to use a domain name to do that. I want to do all of this without having to upload a web site, and all. I hear it is possable to type your ip address into a browser and connect with your home server. please help thank you and good bye.
  • 0

#2 Flying Dutchman

Flying Dutchman

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1090 posts
  • Location:::1
  • Programming Language:C++, Python

Posted 15 February 2012 - 02:42 AM

Most likely you're only listening on localhost. Usually if you specify 0.0.0.0 address, it will listen on all interfaces.
  • 0

The roots of education are bitter, but the fruit is sweet.


#3 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 11 April 2012 - 10:12 PM

I just made a testing of the concept you said and found that it is working on my machine.

Here is the C# code...

string hostname = Dns.GetHostName();
IPAddress ip = Dns.GetHostByName(hostname).AddressList[0];
/* This ip address is 192.168.1.32 */

IPEndPoint endpoint = new IPEndPoint(ip, 7799);  //saving ip &port number
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //installing a new socket!
socket.Bind(endpoint); //making bind function by nameing it ipendpoint!!!
socket.Listen(5);  //number of syste's it's going to listen to....
socket = socket.Accept();   //accept's things. we will get client end to communicate with client
byte[] data = new byte[50000]; //makeing array to get data from client!!!
socket.Receive(data);  //receive the"data" from client!
textBox1.AppendText(Encoding.ASCII.GetString(data)); // let us see what we got from browser


And while put 192.168.132.1:7799 in a tab in my chrome browser and hit it, I got the following data from browser...

GET / HTTP/1.1
Host: 192.168.132.1:7799
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download