Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 117,291 times

Contents

Downloads

Related Categories

Client Server Programming with Winsock - Creating the Client

S.S. Ahmed

Creating the Client

In the sample provided with this article, we are going to create two applications, one server and client. This is a real world example, where the clients requests some information from the server and the server retrieves some specific information from the database and sends the retrieved information back to the client. The database used in the sample is also provided with the code. The database name is Prices.mdb. This is a small database comprising of a single table containing two fields. The fields are item number and price. The clients sends the item number to the server and the server retrieves the price against that item number from the database and sends it back to the client. One of the current trends in software development today is the issue of thick clients versus thin clients. A thick client is basically an application that performs the bulk of the processing on the individual client PC, whereas a thin client performs the processing on the server.

Creating the Client

Follow the steps shown below:

1. Start a new EXE project.
2. Add a Winsock control to your application.
3. Add all the controls to the form (See the application for details).

Here is the complete code:

Option Explicit

Private Sub cmdClose_Click()
Winsock1.Close
shpGo.Visible = False
shpWait.Visible = False
shpError.Visible = True
End Sub

Private Sub cmdConnect_Click()
    Winsock1.RemoteHost = "11.0.0.1" 'Change this to your host ip
    Winsock1.RemotePort = 1007
    Winsock1.Connect
    shpGo.Visible = True
    txtItem.SetFocus
End Sub

Private Sub cmdSend_Click()
    If Winsock1.State = sckConnected Then
        Winsock1.SendData txtItem.Text
        shpGo.Visible = True
        Label3.Caption = "Sending Data"
    Else
        shpGo.Visible = False
        shpWait.Visible = False
        shpError.Visible = True
        Label3.Caption = "Not currently connected to host"
    End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim sData As String
    Winsock1.GetData sData, vbString
    'Label1.Caption = sData
    txtPrice.Text = sData
    Label3.Caption = "Received Data"
    shpGo.Visible = True
    shpWait.Visible = False
    shpError.Visible = False

End Sub

Private Sub Winsock1_SendComplete()

Label3.Caption = "Completed Data Transmission"

End Sub

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic web sites. He has been working with SharePoint for the last 3-4 years. He develops customized SharePoint solutions. Ahmed likes to hop into other tools as well. Ahmed has used Project Server, InfoPath and BizTalk. Ahmed enjoys travelling and has been to many parts of the world. Web: www.walisystems.com Blog: www.sharepointblogs.com/ssa

Comments

  • Posted by ShadowMan on 07 Jun 2005

    you can check your answers here :) hahahaa

  • Posted by pacesetas on 03 Jun 2005

    i want to know how to transfer images that are in the picture1.picture box from a client to another picture1.picture to the server using winsock control, anyone could help me out in this matter, also ...

  • Image transfer through winsock in VB.NET or VB6

    Posted by ShadowMan on 04 Sep 2004

    i want to know how to transfer images that are in the picture1.picture box from a client to another picture1.picture to the server using winsock control, anyone could help me out in this matter, also ...

  • ftp

    Posted by tareket on 07 Jul 2004


    i want to transfere a file using C#
    either ftp or winsock
    if anyone knows how
    please help
    thank u

  • hi

    Posted by tareket on 07 Jul 2004