Click here to Skip to main content
15,909,503 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Is the Screensaver running? Pin
Roidzo6-Jan-04 17:47
Roidzo6-Jan-04 17:47 
GeneralRe: Is the Screensaver running? Pin
Dave Kreskowiak7-Jan-04 5:03
mveDave Kreskowiak7-Jan-04 5:03 
GeneralRe: Is the Screensaver running? Pin
Roidzo7-Jan-04 7:53
Roidzo7-Jan-04 7:53 
GeneralRe: Is the Screensaver running? Pin
Dave Kreskowiak8-Jan-04 4:09
mveDave Kreskowiak8-Jan-04 4:09 
GeneralNew Project Pin
SLoughins6-Jan-04 0:38
SLoughins6-Jan-04 0:38 
GeneralRe: New Project Pin
cnurse6-Jan-04 1:59
cnurse6-Jan-04 1:59 
GeneralRe: New Project Pin
Niels Penneman6-Jan-04 11:10
Niels Penneman6-Jan-04 11:10 
Generalfreezing issue with simple client/server Pin
acecase6-Jan-04 0:04
acecase6-Jan-04 0:04 
Hello,
I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and can't see that I am doing anything wrong (i obviousely am though)

everything "works", client connects to server and when anything is sent to the server it starts the mp3 and passes all messages the way i ment for it to except that my server is supposed to display the data it recieves in a window (that worked untill i changed some things) and my server will hang after I pass a few strings to it from the client.

The hanging is what I can't figure out. I can debug the other no problem.

Anyway here is the code, please look over how sloppy it has gotten after hours of changeing things arround.


Server :


Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class Form1
Inherits System.Windows.Forms.Form

'Windows Form Designer Generated Code was here "removed for size of post"

Const port As Int32 = 8353
Dim localIp As IPAddress = IPAddress.Parse("127.0.0.1")
Dim server As New TcpListener(localIp, port)
Dim netStream As NetworkStream

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'start tcplistener on localhost: 8353
server.Start()

Try
'accept connections
Dim client As TcpClient = server.AcceptTcpClient()

'get stream
netStream = client.GetStream

While netStream.CanRead And netStream.CanWrite


'read stream into a byte array
Dim reciveBufferSize(client.ReceiveBufferSize) As Byte
netStream.Read(reciveBufferSize, 0, CInt(client.ReceiveBufferSize))

'convert data from the client into a usable string variable
Dim dataFromClient As String = Encoding.ASCII.GetString(reciveBufferSize)

'do something with the data
TextBox2.Text = dataFromClient

'send a response to the client
Dim serverResponse As String = "Transmision completed"
Dim sendBufferSize As [Byte]() = Encoding.ASCII.GetBytes(serverResponse)
netStream.Write(sendBufferSize, 0, sendBufferSize.Length)

'show what was sent
TextBox1.Text = serverResponse

If dataFromClient.ToString > "" Then
System.Diagnostics.Process.Start("C:\Documents and Settings\devan\My Documents\my music\christian\Did You Feel the Mountains Tremble_ (1).mp3")
End If
End While
Catch exc As Exception
MessageBox.Show(exc.ToString)

End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
server.Stop()
End Sub
End Class







Client:



Imports System.net
Imports System.Net.Sockets
Imports System.Text


Public Class Form1
Inherits System.Windows.Forms.Form



'Windows Form Designer Generated Code was here "removed for size of post"


Dim client As New TcpClient
Dim netStream As NetworkStream


'If theres a problem check if this should be public for both client and server
Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'establish connection

client.Connect("127.0.0.1", 8353)

netStream = client.GetStream

'show connection status
If netStream.CanRead And netStream.CanWrite Then
StatusBar1.Text = "connected"


''do simple write
'Dim clientCommand As String
'clientCommand = TextBox1.Text.ToString
'Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(clientCommand)
'netStream.Write(sendBytes, 0, sendBytes.Length)

'' Read the NetworkStream into a byte buffer.
'Dim bytes(client.ReceiveBufferSize) As Byte
'netStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))

''Do something with data from server
'Dim dataFromServer As String = Encoding.ASCII.GetString(bytes)
'Label2.Text = dataFromServer.ToString

Else
If netStream.CanRead = False Then
StatusBar1.Text = "cannot write to stream"
Else
If netStream.CanWrite = False Then
StatusBar1.Text = "cannot read stream"
End If
End If

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


'do simple write
Dim clientCommand As String
clientCommand = TextBox1.Text.ToString
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(clientCommand)
netStream.Write(sendBytes, 0, sendBytes.Length)

' Read the NetworkStream into a byte buffer.
Dim bytes(client.ReceiveBufferSize) As Byte
netStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))

'Do something with data from server
Dim dataFromServer As String = Encoding.ASCII.GetString(bytes)
Label2.Text = dataFromServer.ToString
End Sub
End Class




Thanks in advance if anyone can help me figure this out.
GeneralRe: freezing issue with simple client/server Pin
cnurse6-Jan-04 2:09
cnurse6-Jan-04 2:09 
GeneralRe: freezing issue with simple client/server Pin
acecase6-Jan-04 10:03
acecase6-Jan-04 10:03 
GeneralAll Controls in Form Pin
Het21095-Jan-04 21:59
Het21095-Jan-04 21:59 
GeneralRe: All Controls in Form Pin
cnurse6-Jan-04 1:55
cnurse6-Jan-04 1:55 
Generallinking vb.net user interface with c++ dll function Pin
Member 7803585-Jan-04 20:07
Member 7803585-Jan-04 20:07 
GeneralRe: linking vb.net user interface with c++ dll function Pin
Colin Angus Mackay6-Jan-04 4:28
Colin Angus Mackay6-Jan-04 4:28 
GeneralRe: linking vb.net user interface with c++ dll function Pin
Dave Kreskowiak6-Jan-04 9:34
mveDave Kreskowiak6-Jan-04 9:34 
Generalattachments in Word Document Pin
Anonymous5-Jan-04 7:31
Anonymous5-Jan-04 7:31 
GeneralI Don't wanna go to Add/Remove Program to Uninstall my application Pin
jlizardo5-Jan-04 7:29
jlizardo5-Jan-04 7:29 
GeneralRe: I Don't wanna go to Add/Remove Program to Uninstall my application Pin
Niels Penneman6-Jan-04 11:15
Niels Penneman6-Jan-04 11:15 
GeneralRe: I Don't wanna go to Add/Remove Program to Uninstall my application Pin
jlizardo6-Jan-04 16:33
jlizardo6-Jan-04 16:33 
GeneralRe: I Don't wanna go to Add/Remove Program to Uninstall my application Pin
jlizardo7-Jan-04 3:04
jlizardo7-Jan-04 3:04 
QuestionAnyone know's about bootstrapper plug-in.? Pin
jlizardo5-Jan-04 5:10
jlizardo5-Jan-04 5:10 
AnswerRe: Anyone know's about bootstrapper plug-in.? Pin
Niels Penneman6-Jan-04 11:21
Niels Penneman6-Jan-04 11:21 
Questionhow to implement regional font in VB 6.0 ? Pin
Mohan G5-Jan-04 5:06
Mohan G5-Jan-04 5:06 
AnswerRe: how to implement regional font in VB 6.0 ? Pin
Dave Kreskowiak6-Jan-04 4:28
mveDave Kreskowiak6-Jan-04 4:28 
GeneralRe: how to implement regional font in VB 6.0 ? Pin
Mohan G8-Jan-04 4:19
Mohan G8-Jan-04 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.