Solved

Get Acknowledgement using Winsock..

Posted on 2002-04-13
9
757 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now