Re: wxEuphoria--is_connected(atom socket)
- Posted by Mario Steele <eumario at trilake.net> Apr 06, 2005
- 424 views
Ahh, the age old question, What is a socket, and why do they call it a socket? Well, in the simplistic of terms, we'll use a Regular phone as an example. Think of a Client, as you calling a friend. Your friend would be considered the server. Basically, it's up to your friend weither he wants to talk with you or not, so he would either answer the phone, or not answer it. This terminology applies to a server. When you develop a client, it places a call to the server, requesting a confrence. Depending on weither or not the server is listening for the call, or willing to accept your client's call, it'll answer it, and begin the transmission of data, or in the case of the Phone call, pick up, and start talking. Why is it Called a socket? Well, it's called a socket, because it was the ideal back in 88 or so, that when you make a connection between two computers, your basically plugging one computer into another, and that other one has to have a "socket" that the connection can fit into. And the same follows for the socket that you use today in TCP/IP Communications. Basically the socket will either connect, if it can fit into the socket on the server, or it'll fail. Simple as that, eh? Basically, to determin weither or not your connected to the internet, as pre-suggested by Matt, you follow the method of something like this:
include wxEuphoria.e include wxNet.e object void constant cip = create( wxIPV4address, {} ), client = create( wxSocketClient, wxSOCKET_WAITALL ) void = set_ip_host(cip, "64.233.167.104") -- ping www.google.com void = set_ip_service(cip, 80) -- Web Server Port if socket_connect(client,cip,1) = 0 then puts(1,"You are not connected to the internet!") else delete_instance(client) puts(1,"You are connected to the internet!") end if machine_proc(26,0) -- wait_key()
That would be the easy example, and un-tested, as I'm still not familiar with wxEuphoria yet. Mario Steele http://enchantedblade.trilake.net Attaining World Dominiation, one byte at a time...