|
-
Aug 15th, 2003, 09:30 AM
#1
Thread Starter
Addicted Member
Socket Problems [Resolved]
Hi all,
Sorry to post a big chunk of code like this and ask 'what’s wrong', it seems lazy, but I've read as much as I can find and I still can't figure out how to fix this... I'm stuck!
I'm trying to write a client program which will send data to a server program, waits for a reply and then receives the data sent from the server.
Here's my code, it works if I step through it slowly in debugging mode, but not if I run it normally.
VB Code:
Const READ_BUFFER_SIZE As Integer = 255
Const PORT_NUM As Integer = 2100
Private client As TcpClient
Private readBuffer(READ_BUFFER_SIZE) As Byte
Private Sub SendData(ByVal data As String)
client = New TcpClient("localhost", PORT_NUM)
client.ReceiveTimeout = 500
' Send request to server
Dim writer As New IO.StreamWriter(client.GetStream)
writer.Write(data & vbCr)
writer.Flush()
' Receive reply and display in messagebox
Dim networkStream As NetworkStream = client.GetStream()
Dim bytes(client.ReceiveBufferSize) As Byte
Dim returndata As String
While networkStream.DataAvailable
networkStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
returndata = returndata & Encoding.ASCII.GetString(bytes)
End While
networkStream.Close()
MsgBox(returndata)
client.Close()
client = Nothing
End Sub
Hopefully someone out there has some expertise with socket programming and can help me out.
Thanks!
Justin.
Last edited by Justy; Aug 26th, 2003 at 03:21 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|