Solved

Get Acknowledgement using Winsock..

Posted on 2002-04-13
9
761 Views
Last Modified: 2013-11-13
hi experts..
i'm writing a client server application using winsock.

How can my host application send acknowledgement to the client when it receives message from the client? is it my client winsock will also need to listen for incoming message??

i'll be appreciate it if u can send me some sample program for this.

please guide..

thanks



0
Comment
Question by:pleasure
  • 4
  • 4
9 Comments
 
LVL 2

Expert Comment

by:tppradeep18
ID: 6938600
You client program does not need to listen. Once the client has establish connection with the server, the serve can send the acknowledgement throught the new socket and port created by it automatically.

there are lots of articles on the internet that exactly tells you how to do it. Here is a good link to start with

www.vb-world.net/internet/winsock/ 

hope this helps
0
 
LVL 2

Expert Comment

by:tppradeep18
ID: 6938602
you can download a good sample applicatoin from

www.freevbcode.com/source/winsock1.zip

0
 

Author Comment

by:pleasure
ID: 6938687
i'm facing a problem... when i use a for loop to send data
eg :
For i = 0 To 9
       socketClient.SendData CStr(i)
Next i

my server application will receive "0123456789" instead of receiving each number separately...can u tell what is the problem here???
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:pleasure
ID: 6938752
myt client is actually will receive an acknowledgment when it sends message to server.. what i'm worried is when my client send multiple messages at the same time.. will it be able to receive the acknowledgement??

i'm using VB6 to develope the application... from the experiment i did.. i found that the client server cannot cope with this... any suggestion??

please guide...
0
 
LVL 2

Expert Comment

by:Ber
ID: 6938915
If you want the client to recieve an acknowledgement for every message sent then you should hold the transmission on the client side until the server has sent an acknowledgement .Once acknowledgement is recieved transmit the next message...

Cheers...
Ber...
0
 

Author Comment

by:pleasure
ID: 6938920
hi Ber...
thanks for your opinion..but do you have any sample for this type of application??? how could i know either the client had received acknowledgment from server??
0
 
LVL 2

Expert Comment

by:tppradeep18
ID: 6939969
I am giving below two modules - Client and server. This code assumes that you are using a single machine for both client and server. Two seprate computers can also be used. for this change remotehost property in Client module.



Open a new project for client. Add two command buttons - command1,command2. Add a textbox - text1. Add winsock control - tcpClient.

paste the following code in form module

'***** Client Module *****

Dim blnAck As Boolean
Private Sub command2_Click()
For i = 1 To 5
tcpClient.SendData i
Do While True
  DoEvents
  If blnAck Then
    blnAck = False
    Exit Do
  End If
Loop
Next

End Sub

Private Sub Form_Load()
    command1.Caption = "Connect"
    command2.Caption = "Send Message"
    tcpClient.RemoteHost = "Localhost"
    tcpClient.RemotePort = 1001
End Sub
Private Sub command1_Click()
    ' Invoke the Connect method to initiate a
    ' connection.
    tcpClient.Connect
End Sub
Private Sub txtSendData_Change()
    tcpClient.SendData txtSend.Text
End Sub
Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
    Dim strData As String
    tcpClient.GetData strData
    blnAck = True
End Sub

'***** End of Client Module *****


Open a new project for Servermodule. Paste the following module in form module.

'************* server module

Private Sub Form_Load()
    ' Set the LocalPort property to an integer.
    ' Then invoke the Listen method.
    tcpServer.LocalPort = 1001
    tcpServer.Listen
   
End Sub

Private Sub tcpServer_ConnectionRequest _
(ByVal requestID As Long)
    ' Check if the control's State is closed. If not,
    ' close the connection before accepting the new
    ' connection.
    If tcpServer.State <> sckClosed Then _
    tcpServer.Close
    ' Accept the request with the requestID
    ' parameter.
    tcpServer.Accept requestID
End Sub

Private Sub txtSendData_Change()
    ' The TextBox control named txtSendData
    ' contains the data to be sent. Whenever the user
    ' types into the  textbox, the  string is sent
    ' using the SendData method.
    tcpServer.SendData txtSendData.Text
End Sub
Private Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
    ' Declare a variable for the incoming data.
    ' Invoke the GetData method and set the Text
    ' property of a TextBox named txtOutput to
    ' the data.
    Dim strData As String
    tcpServer.GetData strData
    tcpServer.SendData "Received"
End Sub










0
 

Author Comment

by:pleasure
ID: 6941702
tppradeep18,
thanks for your sample.. but what actually i need to know is when my client send data to the server, can i receive data from server at the same time?
0
 
LVL 2

Accepted Solution

by:
tppradeep18 earned 50 total points
ID: 6943539
When client has sent data, the server has to receive it first of all to send you any sort of acknowledgement. In you case you will have to WAIT to get this acknowledgement before you can send any second message .  The client receives this acknowlegement through dataarrival event. There is no way to receive data from server at the same time. Information between a client to server follows a pattern and you have to follow this pattern
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question