Real Software Forums
http://forums.realsoftware.com/

TCPSocet
http://forums.realsoftware.com/viewtopic.php?f=2&t=46350
Page 1 of 1

Author:  besoft [ Wed Dec 26, 2012 3:35 am ]
Post subject:  TCPSocet

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

Author:  p0wn3d [ Wed Dec 26, 2012 10:08 am ]
Post subject:  Re: TCPSocet

:?:

What type of device are you wanting to monitor?

Author:  besoft [ Wed Dec 26, 2012 11:17 am ]
Post subject:  Re: TCPSocet

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.

Author:  timhare [ Wed Dec 26, 2012 1:58 pm ]
Post subject:  Re: TCPSocet

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.

Author:  besoft [ Thu Dec 27, 2012 2:33 am ]
Post subject:  Re: TCPSocet

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

Author:  timhare [ Thu Dec 27, 2012 3:08 am ]
Post subject:  Re: TCPSocet

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?

Author:  besoft [ Thu Dec 27, 2012 3:52 am ]
Post subject:  Re: TCPSocet

I get no messages, the application stops responding .. I'll still try to explore a little.

Author:  msssltd [ Sat Dec 29, 2012 4:04 am ]
Post subject:  Re: TCPSocet

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

Author:  simulanics [ Sat Dec 29, 2012 9:55 am ]
Post subject:  Re: TCPSocet

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 :-)

Author:  simulanics [ Sat Dec 29, 2012 9:59 am ]
Post subject:  Re: TCPSocet

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 :-)

Author:  besoft [ Sun Dec 30, 2012 1:39 pm ]
Post subject:  Re: TCPSocet

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

Author:  simulanics [ Sun Dec 30, 2012 3:26 pm ]
Post subject:  Re: TCPSocet

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 :-)

Author:  timhare [ Sun Dec 30, 2012 9:29 pm ]
Post subject:  Re: TCPSocet

ServerSocket will work for incoming connections. If you are connecting to a list of servers, use an array of TCPSockets.

Author:  besoft [ Mon Dec 31, 2012 3:39 am ]
Post subject:  Re: TCPSocet

can anyone have an example?
thank you

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/