• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Delphi Programming question

I can't setup my socket to listen at my IP addres.
I don't know if this is Windows Configuration error or i made error in code.

What i'm doing :
I have single PC with NetworkCard. TCPIP and NetBUI, but Dialup adapter too with different TCPIP settings.
I need write and test InternetWWW server.
I create socket and place to Listen mode, i have message procedure for WM_ASYNCSELECTand I call WSAASyncSelect(..)

but when i run IE3.0 it can't connect to my IP or name.

When I setup socket with :
sin.sin_family := AF_INET;
sin.sin_addr.s_addr := INADDR_ANY;
i can connect only to

How can i setup socket to listen on My IP?
1 Solution
mirek071497Author Commented:
Adjusted points to 80
mirek071497Author Commented:
Adjusted points to 100
mirek071497Author Commented:
I run Server and IE3.0 on the same PC. Mayby the problem is here?
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

This defenatly looks like what you surgestied your self. That you have a dialup adapter with a different IP setting. I have experinced a similar problem, and also when I was just trying to connect to a network. If the dialup adapter had a different setting, then I would not work. Try and set the two things alike, and see if it works, then you will know if that is the problem.
mirek071497Author Commented:
I remove Dialup adapter from My System and i have the same problem.
I think so i must made error with usage of socket functions.
Please try find what i'm doing wrong.

When I don't set My IP then i can listen on IP=
but how can i listen on MyIP;

procedure TSockets.SListen;
  iStatus: integer;
  szTcp: PChar;
  szPort: array[0..31] of char;
  szData: array[0..256] of char;
  Phe: PHostEnt;
  szHostName: array[0..128] of char;

  FPort = '80';
  { sin is TSockAddrIn }
  sin.sin_family := AF_INET;
  sin.sin_addr.s_addr := INADDR_ANY;

  { this is for set my IP }
  Phe := GetHostByName(szHostName);
  if Phe <> nil then
    sin.sin_addr.s_addr := longint(plongint(Phe^.h_addr_list^)^);

  { show message for test if correct IP was assigned }
  ShowMessage ( inet_ntoa(sin.sin_addr) );

  szTcp := 'tcp';
  Pse := getservbyname(szPort,szTcp);
  if Pse = nil then
    sin.sin_port := htons(StrToInt(StrPas(szPort)))
    sin.sin_port := Pse^.s_port;
  Ppe := getprotobyname(szTcp);

  FMSocket := socket(PF_INET,SOCK_STREAM,Ppe^.p_proto);
  if FMSocket < 0 then

  iStatus := bind(FMSocket, sin, sizeof(sin));
  if iStatus <> 0 then
  iStatus := listen(FMSocket,5);
  if iStatus <> 0 then
  if FMode = 1 then
    iStatus := WSAASyncSelect(FMSocket,Handle,WM_ASYNCSELECT,
    if iStatus <> 0 then
  else ioctlsocket(FMSocket,FIONBIO,FMode);

mirek071497Author Commented:
Adjusted points to 120
mirek071497Author Commented:
Adjusted points to 133
First thing that I can see is that your 'sin' is unsassigned at
the start of the function call... is it global? And if so, are you _Sure_ it's set to something sensible because your GetHostByName() call is going to fall over without a DNS set.

My best bet is that there's a problem with your win setup. Working TCP/IP programming withouth more than 1 mahcine is a real pain in the ass.
mirek071497Author Commented:
Hi AjFleming !
thanx for comment. I newbie with server socket programming so if you have time i give you points with A for some talk here.

1.I found so i don't need set my IP and i can't set my IP when i need make connections from more than one networks. Is this correct ?
2.I think so i have error with socket number. Do you know sockets number which is for use with WWW and other ? (some i know i.e. echo=7, mail=25 .... )
3.Can you help me vith basic principies of setting up sockets for servers ?

mirek071497Author Commented:
Hi All. I found the solution !

IP is for the wire to host not for the host (example : when you have more than one wires to network you need more than one IP!) and in result I can't call my machine with their IP.
IP 127.any.any.any is for call to local host only and this is the answer.

I wait 3 days to give you time to read this and i delete this question.
I'm posting the solution so the answer can be saved in the PAQ.

Hi All. I found the solution !

IP is for the wire to host not for the host (example : when you have more than one wires to network you need more than one IP!) and in result I can't call my machine with their IP.
IP 127.any.any.any is for call to local host only and this is the answer.
mirek071497Author Commented:
i see so this server have more bugs than Windows95 !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now