Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Sep 20, 2017 2:34 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: TCPSocet
PostPosted: Wed Dec 26, 2012 3:35 am 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
Hello

I want to develop an application to communicate with a device that is connected to the network.
I made the connection, everything works perfectly.
I was wondering how to perform a check, een the device is connected to the network, the application does not crash if the device is disconnected from the network.
Real.studio or to use a function or command PING?

Thank you very much


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Wed Dec 26, 2012 10:08 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:?:

What type of device are you wanting to monitor?

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Wed Dec 26, 2012 11:17 am 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
I use a terminal that I built myself. Ethernet module manufacturer is wiznet.
From the terminal I get a certain string, and sends it back to the terminal. The problem is that if someone removes the terminal from the network, the application detects this and does not crash.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Wed Dec 26, 2012 1:58 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You should handle the error condition in the socket. If you try to write to the socket after the terminal has been removed, you should get an Error event. Put code in there to fail gracefully instead of crashing.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Thu Dec 27, 2012 2:33 am 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
Thanks for the reply

how can I find out if the device is ever on the network before connecting. In fact, if you run an application before the device is on the network crash occurs.

thx


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Thu Dec 27, 2012 3:08 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
How so? You'll just get an Error instead of a Connected event. What kind of crash are you experiencing? An RB exception not handled? An OS crash message?


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Thu Dec 27, 2012 3:52 am 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
I get no messages, the application stops responding .. I'll still try to explore a little.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sat Dec 29, 2012 4:04 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
It sounds like you need a timeout mechanism.

Here is an example which waits 2 seconds for a socket to become connected
const time_out = 2000000
dim toStart as double

TCPSocket1.Connect
Do
TCPSocket1.Poll
Loop Until TCPSocket1.IsConnected or (Microseconds - toStart > time_out)

If Not TCPSocket1.IsConnected then
msgBox "Connection timed out. Check device is available."
TCPSoclet1.Close
Return
End If

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sat Dec 29, 2012 9:55 am 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
Use the autoDiscovery class

In open event of your app

ADControl.bind(2738) 'port

In the MemberJoined(ip) event

Dim hostname as string=System.Network.lookipdnsname(ip)
'this will be computer name of apps on the network
Do whatever you need here...for example use the tcpsocket now to connect...we know the users available.

In both apps you will need to call
ADControl.register("my group")
'will add the user to a multicast named "my group"
'users in this group will immediately receive the member joined group

In close event
ADControl.unregister(my group)

**you can have more than one multicast name!

If you need a tcpsocket based method, I've written a network "port scanner" that can search a network for specifically open ports...if you are networked though, your best solution is the AutoDiscovery class :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Last edited by simulanics on Sat Dec 29, 2012 10:01 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sat Dec 29, 2012 9:59 am 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
If you dont have access to the code of the item you are monitoring.. You can use the Shell class and issue a "ping 192.168.1.5:4848" and if the device has a port open it will return that all packets were received :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sun Dec 30, 2012 1:39 pm 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
Problem solved by using a code that you sent my msssltd with some modifications.

One more question. I have a ListView control that contains data. I would like to open as many connections using TCPsocet control how many records in the ListView control.

Something like this:
ListView control contains data: ID, host, port. For each row should open TCPSocet.

Can you advise how?

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sun Dec 30, 2012 3:26 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
Add a ServerSocket and in the add socket event put

Return new TCPSocket1

Then you can call them as such

Dim mysocks() as tcpsocket = nameofserversocket.activeconnections

Then if u want to send to the first socket

Mysock(0).write "data"

If you want connection number 3...

Mysock(2).write (or any property of mysock)

I'm actually almost ready to release a class set of server/client that you can drop in your apps and it'll handle all data transactions and cross interactions..
Such as an instant messenger :-) They map all connections as well automatically and you can call socks as socks or by 'user identifier' (name or whatever's passed to identify the connected clients :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Sun Dec 30, 2012 9:29 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
ServerSocket will work for incoming connections. If you are connecting to a list of servers, use an array of TCPSockets.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocet
PostPosted: Mon Dec 31, 2012 3:39 am 
Offline

Joined: Wed Dec 26, 2012 3:28 am
Posts: 9
can anyone have an example?
thank you


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group