• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Get Acknowledgement using Winsock..

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
pleasure
Asked:
pleasure
  • 4
  • 4
1 Solution
 
tppradeep18Commented:
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
 
tppradeep18Commented:
you can download a good sample applicatoin from

www.freevbcode.com/source/winsock1.zip

0
 
pleasureAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
pleasureAuthor Commented:
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
 
BerCommented:
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
 
pleasureAuthor Commented:
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
 
tppradeep18Commented:
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
 
pleasureAuthor Commented:
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
 
tppradeep18Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now