Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / IP address

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. IP address
#855
Posted by: cajino 2003-04-15 22:28:51
I need a program which shows the IP address of the PC where it's running.
Sort of "your current IP address is....", but not on the net, on a local machine with fixed IP.
Can someone help me?

Thanks

Cajino
Message2. Re: IP address
#856
Posted by: guidance 2003-04-16 06:50:34
RSocket doesn't work?

http://g.yi.org/_scripts/file.php?f=5843&r=2330
Message3. Re: IP address
#857
Posted by: cajino 2003-04-16 14:48:48
As I see it, RSocket needs to be connected to a host, while I need a standalone application (GUI) showing me some system parameters (IP address, environment variables etc.).

Bye
Message4. Re: IP address
#858
Posted by: guidance 2003-04-16 18:34:50
Have you tried all examples come together with RSocket?
Message5. Re: IP address
#859
Posted by: cajino 2003-04-16 22:13:07
I didn't find what I needed there, my guess is that I have to use the API function GetIpAddrTable, but I couldn't make it work.
Also, it's not in the WIN32API.INC file.
Hope someone can help.

Bye
Message6. Re: IP address
#860
Posted by: 2003-04-17 00:58:32
Look at my Server_Client code - I did it for home networking
as well as the net. You need to call the gethostby() functions.
If you have the name of the client machine, you simply pass it
to gethostbyadr() which in turn gives you an hostent structure
with ip address, alias names etc (alothough the alias names are
best left to c programming).

regards

john

P.s: The rsocket include file covers these calls as well.
Message7. Re: IP address
#862
Posted by: cajino 2003-04-17 15:25:27
Gosh, this is going far above my skills...
How do I get the local machine name?

Thanks alot

Cajino
Message8. Re: IP address
#864
Posted by: 2003-04-17 20:03:05
I need a program which shows the IP address of the PC where it's running.

So you know its name if its not on the net? I.e is it on direct cable
connect?

Sort of "your current IP address is....", but not on the net, on a local machine with fixed IP.

You can also have a program (client) on the client machine, which is only
natural if two programs are to talk to each other, that tells it name to
itself.

As said, look at the server_client code. You have the server on your machine and the client on every other machine. You could then send a
string to the client and vice versa saying:

server "hello - my name is server_john"

client  looks up server_john`s ip and then:
client "Did you know your ip address is: "+ip$

server "wow thanks! I know your ip address as well"

regards

john
Message9. Re: IP address
#871
Posted by: cajino 2003-04-23 15:33:40
Thank you guys for your help.
I guess the best solution will be QSocket after all, I'm trying John's idea of a server and a client exchanging informations using Yu's chat server and so far it seems to work.
I tried Server_Client, but running in Win95 or 98 I got a run-time error 216, while it worked in Win2000.
Have a nice day.

Cajino
Message10. Re: IP address
#873
Posted by: 2003-04-24 03:28:49
Sorry Cajino!! I am now using w2k pro virtually
full time now (It detects my h/w etc better).

Note: The chat/server of w.yu will need modifying
even with 98 if you are going to use it on an
Internet Cafe (more than one computer) if going
via a router. Although you should find the general
idea through that code. I would say RSocket should
be your first choice.

95: Did you change my server/client code to 1.1?
I never tried it but you could drop down to w.sockets
1.1 (257 word value) instead of 2.2 (514 word value).

Incidently. You did not specify your use and connection?
Are you using LAN (cable) connection? How many machines
are you using?.....as you might need to use create process
if using more than 2 machines.

Regards

John
Message11. Re: IP address
#874
Posted by: cajino 2003-04-24 14:50:31
Hi, I'm working in a Lan with about 30-35 clients, half of which will be reached via router. So far I tested Yu's program only with 2 machines and without the router, so maybe I'll have some problems later... thanks for your warning, I guess I'll have a better look at RSocket.
I tried the 1.1 option you suggested (in W98), but still got that error.
Last thing, I don't know what create process means... can you show me an example?

Thanks

Cajino
Message12. Re: IP address
#875
Posted by: 2003-04-24 23:17:47
Hmm!!! Now you`re asking!!!

Basically. What are you going to do when you have
say two clients hitting you at the same time? How
will you identify each one? Soultion: You have to store
the ip (hostent) details for each connected client and then
monitor their READ/WRITE actions in a seperate process.
If you do not your program (server) will be prone to all soughts
of disasterous problems later......like the Bottle Neck effect. I.e
imagine a bottle`s neck. One match stick (client) might get out
of the bottle, but when you try and shake all the matches out
all the matches will get stuck in the neck of the bottle, simply
because there are too many matches trying to get out of the
bottle at one time. Also. If you are sending a message to all
30 machines and expecting 30 messages (READs) back you
have to loop through each one.....which is fine, but what happens
when if whilst retreiving the messages another socket dis/connects
and/or writes a new message (a message you were not expecting?).

By creating a thread/process for each connected socket, each seperate
process/thread takes care of reading/writing for you. I.e it monitor
a particular client whilst the server is listening for new connections,
disconnections, etc.

These comments only apply if you are creating an Internet Cafe style
program. Like your router and 30 machines, whereby you put a client
program on each machine. I am currently writing a similar program in C,
but I am using MS`s _beginthread() function (not available in RapidQ?).

RSocket will probably help you partly, but I`m not sure if RSockets
takes the Bottle Neck/Process/Thread into account?

Server/Client: Sorry again! I forgot that those instructions (APIs) are
w2k only....if I remember correctly.

regards

john
Message13. Re: IP address
#876
Posted by: 2003-04-27 12:06:51
My GypsyProxy program in RQ may address both of these problems.
1. It gets local IP and local name like this:
LocalIP = Peer.GetHostIP
Statusbar.Panel(2).Caption = LocalIP
LocalName = Peer.NamebyAddr(LocalIP)
Statusbar.Panel(1).Caption = LocalName
The .NamebyAddr(ip$) function is defined in Rsocket.inc

2. While you can get results with separate threads for separate server clients (connections), for a moderate level of traffic it is best to avoid that complication.
Create an array of listening ports like this:
nServers=n 
FOR n=1 to nServers
Sock(n) = Peer.Open(Port(n))
IF Sock(n)<=0 THEN ShowDat "Server Error, Port "+STR$(Port(n)): Goto ServerDone
ret = Peer.NonBlock(Sock(n))
NEXT n
The Port(n) array contains the port numbers, and Sock(n) are the socket handles associated with each listening port.  Then:
You loop for ever, putting a liberal sleep after each loop cycle.  [The real work is done at the socket level and your program need not loop too rapidly.]
CheckIfReady:
S=Sock(n)
IF Peer.ConnectionReady(S) <= 0 THEN Goto NextListenPort
cS=Peer.Accept(S): t$ = Peer.GetPeerName(cS)
Above is part of loop to check for new connections.  We get the handle S and check if we have a visitor and if so accept it, where cS is the client socket handle and t$ is the client IP address.
NOW we are going to have as many arrays as we need to keep track of each client online.
AcceptPeer:
cSock(m)=cS: Serv(m)=Port(n): cIP(m)= t$: Time(m)=Timer: Logon(m)=Timer
Above we see from GypsyProxy that cSock() stores the handle, Serv() stores the port (so we know what to do with it) and we have the IPaddress in cIP(), time in Time() and time of logon as Logon().
Now, to sum up, you have two loops all the time and plenty of sleep.
Loop 1 = check for new connection as above, Loop 2 = service existing connections.  I do not use QTimer, it is simply too much trouble.  I just update Time() when I want to, and in Loop 2, check if Timer-Time(m) > constant, and if so, the connection has timed out and is closed.  Of course, various protocols might also result in closing a connection.  Note above m is the connection being serviced at the time.  If Serv(m)=0 there is no connection, If not 0, there is one and we service it.  If some activity occurs in connection m, then Time(m) can be updated: Time(m)=Timer.  Thus, a simple timeout can be done which is easy (QTimer is more complicated and therefore hard).
That is how GypsyProxy is set up and it works very reliably.  I just added CGI/1.1 to the web server in it.  Good luck!
In sum, just changing the value of m, "selects" the socket to be serviced (a lot more easy than doing separate threads).  Just make an Array(m) for whatever you need that pertains to a particular connection.  I have one called Act(m) which is the "state" of a connection.  Thus, in each loop one can simply SELECT CASE Act(m) and off you go to do exactly what that particular connection needs at that moment.
Message14. Re: IP address
#879
Posted by: cajino 2003-04-28 14:46:47
Wow guys, that's a lot to work on. I'll have to sweat it out bit, but I think I got what I needed.
BTW, is GypsyProxy source availeble somewhere?

Thank you very much.

Cajino
Message15. Re: IP address
#880
Posted by: 2003-04-28 20:09:43
A bit late maybe :) !

This works too :

' ----------
Dim Me as QSocket ' and probably with Rsocket too
DefStr LocalName, LocalIP
LocalName = Me.GetHostName
LocalIP = Me.GetHostIP

Print LocalName;"   ";LocalIp
' ----------

Jacques
Message16. Re: IP address
#890
Posted by: 2003-05-09 03:32:30
Obligation prevents release of complete source, but I already posted the meat of what source you need.  Also, I can post other coding techniques as questions arise.  Just email me.  Yours, doc
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0