VB.net CLient/Server APP

5 pts.
Tags:
Client-server
VB.NET
The client talks to the server fine but all of the code I've found said to use the stream to respond back to the client from the server. However the client dies when it tries to read a line back... What's wrong? How can I make the response happen and what did I do wrong with it? Here's the code: ------========CLIENT=======------- Imports System.Net.Sockets Imports System.Text Imports System.IO Public Class frmLogin Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Dim client As New TcpClient 'Dim listen As TcpListener client.Connect("127.0.0.1", 2030) Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anyone there?") Dim server As NetworkStream = client.GetStream() If server.CanRead And server.CanWrite Then server.Write(sendBytes, 0, sendBytes.Length) Dim bytes(client.ReceiveBufferSize) As Byte MessageBox.Show(bytes.ToString) server.Read(bytes, 0, CInt(client.ReceiveBufferSize)) '' ''read into the bytes array ' ''server.Read(bytes, 0, CInt(client.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes) Console.Write(returndata) 'MessageBox.Show(returndata) Else MessageBox.Show("Sorry") End If frmMovie.Show() Me.Hide() End Sub End Class --------========SERVER=======----- Imports System.Net.Sockets Imports System.Net Imports System.Text Public Class Form1 Shared Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim listener As TcpListener Dim client As TcpClient Const portNumber As Integer = 2030 Dim localHost As System.Net.IPAddress localHost = IPAddress.Parse("127.0.0.1") listener = New TcpListener(localHost, portNumber) Try listener.Start() Console.Write("Listening for a connection" + vbCrLf) 'rest of server code here 'server blocks client = listener.AcceptTcpClient() 'waiting for a connection Console.Write("Connection accepted" + vbCrLf) 'read the straem Dim networkStream As NetworkStream = client.GetStream() Dim bytes(client.ReceiveBufferSize) As Byte 'read into the bytes array networkStream.Read(bytes, 0, CInt(client.ReceiveBufferSize)) 'convert to string Dim clientData As String = Encoding.ASCII.GetString(bytes) Console.Write(clientData + vbCrLf) '''''''''''output Dim responseString = "Connected to server" Dim sendbytes As [Byte]() = Encoding.ASCII.GetBytes(responseString) networkStream.Write(sendbytes, 0, sendbytes.Length) listener.Stop() Catch ex As Exception End Try End Sub End Class
ASKED: August 21, 2008  4:47 PM
UPDATED: August 21, 2008  4:56 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following