Program flow socket client/server

Simulacra

New member
Joined
Jul 14, 2006
Messages
3
Programming Experience
Beginner
Hello all. Let me preface this post with the obviouse statement that i am new to VB.Net. It has been an interesting learning expereince thus far for me trying to learn the language syntax and VB's nueances. I was tasked with writing a small application that communicates via TCP on port 60000. Here is what I am trying to accomplish.

The server listens on port 60000 for incomming conections. When one comes in it then writes the data to a text file and waits for another connection to come in. After it receives the data it then sends an xml file back to the sending interface ackknwledging that the data was sent successfully.

What I have done so far is piece together a few subs from variouse examples that have been provided online and in books to come up with this rough outline.

VB.NET:
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Xml





Module Module1

    Sub Main()
        
        Dim thdListener As New Thread(New ThreadStart(AddressOf listenerThread))
        Dim alSockets = New ArrayList()
        Dim thdSend As New Thread(New ThreadStart(AddressOf SendACKN))


        
            ' This gets the ball rolling by starting up listenerThread
            ' which in turn calls handlerThread to do the dirty work
            ' of writng to a  text file.  
            
             thdListener.Start()

  


    End Sub

Private alSockets As ArrayList

Public Sub listenerThread() .......

Public Sub handlerThread() .....

Public Sub sendACKN().....


End
So this is where I am stuck at. I need to start thdListener() then when that finishes I need to use sendACKN() to send the file and I am not sure how to do this in the Main() sub?

Any suggestions?

Thanks,

Norm
 
I guess your listenerThread waits to accept a TcpClient then loops to accept the next one etc. When a TcpClient is accepted you should spawn a handleClient thread that will receive the data, once all data is received (*) in that thread you continue in that thread and send the acknowledge in return, then that client session is finished.

(=*) You must find a way for the server to know when all data is received, a simple method is for the client to first send the lenght of bytes it will be sending.

Here is one simple client/server example perhaps useful for you to see http://www.vbdotnetforums.com/showpost.php?p=35284&postcount=7
 
Back
Top