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



pleasureAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.