Solved

Get Acknowledgement using Winsock..

Posted on 2002-04-13
9
763 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

840 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