Hi,

I'm one of the folks who works for Catalyst, the company who makes
SocketWrench. If
you're programming in VB.NET, I'd really recommend using the .NET
Edition rather than
the ActiveX control in the Visual Edition. The ActiveX control is
designed for older languages
like VB6, and there's some inherent overhead for using COM inside .NET
applications.

In any case, if you're looking to create a server application here,
I'd also recommend not
using SocketWrench itself, but instead use our InternetServer
component (it's also included as
part of SocketWrench, but rather than being a more general purpose
component, it's
specifically geared towards creating server applications). It's much,
much simpler to implement
and you don't have to deal with things like creating arrays of client
sockets and all of the
other lower-level management stuff that you need to do with typicaly
socket-based server
implementations. Basically the InternetServer component is a generic
"server in a box" that
you just start and respond to events.

Here's a simple example, using Windows Forms with a single form and
two buttons, one
to start the server and the other to stop it:

Imports SocketTools
Imports SocketTools.InternetServer

Public Class Form1
    Public WithEvents Server As New SocketTools.InternetServer

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        If Server.Initialize() = False Then
            MessageBox.Show("Unable to initialize server component")
            End
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
        ' Start the server listening on a specific address and port
number
        If Server.Start("127.0.0.1", 5000) = False Then
            MessageBox.Show(Server.LastErrorString)
            Exit Sub
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
        ' Stop the running server, disconnecting all clients
        If Server.Stop() = False Then
            MessageBox.Show(Server.LastErrorString)
        End If
    End Sub

    Private Sub Server_OnConnect(ByVal sender As Object, ByVal e As
SocketTools.InternetServer.ConnectEventArgs) Handles Server.OnConnect
        ' The OnConnect event fires when a client connects to the
server
        Server.WriteLine("You have connected to the server")
    End Sub

    Private Sub Server_OnRead(ByVal sender As Object, ByVal e As
SocketTools.InternetServer.ReadEventArgs) Handles Server.OnRead
        ' The OnRead event fires when a client sends data to the
server;
        ' in this example, we're reading complete lines of text and
sending
        ' them back to the client
        Dim strBuffer As String = String.Empty

        If Server.ReadLine(strBuffer) Then
            Server.WriteLine("You sent: " + strBuffer)
        End If
    End Sub
End Class

You could test it out just by using the built-in telnet command from
the command line. In this
case, it would be:

telnet 127.0.0.1 5000

Of course, the IP address and the port number can be specified to
whatever you need. Note that if
you're going to want to connect to this server externally (i.e.:
outside of your own local network), that's
going to involve some additional stuff not directly related to
programming the server. For example,
you'll need to configure your NAT router to redirect external traffic
to the system that's hosting the
server, and you'll need to make sure your firewall is configured
properly to allow the inbound traffic.

If you have questions about SocketWrench or SocketTools, you're also
welcome to register and post
on our forums at http://forums.catalyst.com

Regards,
Mike

On Mar 1, 12:56 am, neddie <[email protected]> wrote:
> Hi to all.
> I am workong on  a project to retrieve data that has been sent from a
> GSM module to my PC via GPRS.
> I am using Socketwrench visual edition(is this the best option?)
> I can't get the OnRead event to fire when data comes into the PC. Any
> idea
> what needs to be setup for this to work.
>
> I have a Socket defined like this
>   Dim WithEvents Socket As New SocketWrench
>
> it initialises with no error.
>
> in the Form Load handler I have:
>  Socket.Enabled = True
>  Socket.Blocking = False
>  Socket.Listen("192.168.40.194", 80)
>
> I have 2 subroutines  , with nothing in them yet.
>  Sub Socket_OnRead()
>  Sub Socket_OnAccept()
>
> If I connect with Hyperterminal , it connects fine. If my VB code is
> not running , Hyperterminal return an error
> , so I know my code seems to be establishing a connection.
> I just can't get any data out , and I'm a bit stuck.
> I'm net to Socketwrench , and fairly new to VB.net , so I may be
> missing something obvious :0(
> Cny help appreciated.
> cheers
> Rob

Reply via email to