Click here to Skip to main content
15,914,642 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Get table field size Pin
Eddy Vluggen5-Aug-10 0:28
professionalEddy Vluggen5-Aug-10 0:28 
QuestionCannot find ContextMenu control in vb.net Pin
Andraw Tang4-Aug-10 6:30
Andraw Tang4-Aug-10 6:30 
AnswerRe: Cannot find ContextMenu control in vb.net Pin
cyberexel4-Aug-10 8:05
cyberexel4-Aug-10 8:05 
GeneralRe: Cannot find ContextMenu control in vb.net Pin
Andraw Tang4-Aug-10 10:25
Andraw Tang4-Aug-10 10:25 
GeneralRe: Cannot find ContextMenu control in vb.net Pin
cyberexel4-Aug-10 23:11
cyberexel4-Aug-10 23:11 
QuestionGet Primary Field and Foreign Fields from Access Table Pin
cyberexel4-Aug-10 4:49
cyberexel4-Aug-10 4:49 
AnswerRe: Get Primary Field and Foreign Fields from Access Table Pin
cyberexel5-Aug-10 6:39
cyberexel5-Aug-10 6:39 
QuestionRemote TCP file Transferring Pin
rezafathi3-Aug-10 14:15
rezafathi3-Aug-10 14:15 
Hi,

I have the below code for transferring file from a client to server. This code works fine but i wanted to know how can i get the file name when i send a file from client to server.when i send a file from client to server a save file dialog will be opened and you i have to write the file name and its extension in order to save it. but i want to get the file name and its extension as it is sent.

//client
Imports System.Threading
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form





Private Sub btBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btBrowse.Click
OpenFileDialog.ShowDialog()
tbFilename.Text = OpenFileDialog.FileName
End Sub

Private Sub btSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSend.Click

Dim filebuffer As Byte()
Dim filestream As Stream
filestream = File.OpenRead(tbFilename.Text)
ReDim filebuffer(filestream.Length)

filestream.Read(filebuffer, 0, filestream.Length)

Dim len As Long = filestream.Length - 1
For i As Long = 0 To len
If i Mod 1000 = 0 Then 'only update UI every 1 Kb copied
ProgressBar1.Value = i * 100 / len
Application.DoEvents()
End If
Next
ProgressBar1.Value = 0
Dim IpHost As IPHostEntry
IpHost = Dns.GetHostByName(tbServer.Text)
Dim clientSocket As New TcpClient(tbServer.Text.ToString, 1234)

Dim networkStream As NetworkStream
networkStream = clientSocket.GetStream()
networkStream.Write(filebuffer, 0, filestream.Length)
End Sub
End Class


///server

Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO


Public Class Form1
Inherits System.Windows.Forms.Form

Dim test = System.Net.IPAddress.Any
Private alSockets As ArrayList


Public Sub listenerThread()
Const portNumber As Integer = 1234
Dim tcpListener As New TcpListener(test, portNumber)
Dim handlerSocket As Socket
Dim thdstHandler As ThreadStart
Dim thdHandler As Thread

tcpListener.Start()
Do
handlerSocket = tcpListener.AcceptSocket()
If handlerSocket.Connected Then
lbConnections.Items.Add( _
handlerSocket.RemoteEndPoint.ToString() + _
" Connected.")

SyncLock (Me)
alSockets.Add(handlerSocket)
End SyncLock
thdstHandler = New ThreadStart(AddressOf _
HandlerThread)
thdHandler = New Thread(thdstHandler)
thdHandler.Start()

End If
Loop
End Sub

Public Sub HandlerThread()

Dim handlerSocket As Socket
handlerSocket = alSockets(alSockets.Count - 1)
Dim networkStream As NetworkStream = New _
NetworkStream(handlerSocket)
Dim blockSize As Int16 = 1024
Dim thisRead As Int16
Dim dataByte(blockSize) As Byte

SyncLock Me
Dim SaveFileName As String = String.Empty
Dim DialogSave As New SaveFileDialog

MessageBox.Show("You have a File", "File transfer", MessageBoxButtons.OK, MessageBoxIcon.Warning)
If MsgBoxResult.Ok Then

Me.Opacity = 100

DialogSave.Filter = "All files (*.*)|*.*|JEPG (*.jpg)|*.jpg"
DialogSave.RestoreDirectory = True
DialogSave.Title = "Where do you want to save the file?"
DialogSave.InitialDirectory = "C:/"
If DialogSave.ShowDialog() = DialogResult.OK Then
SaveFileName = DialogSave.FileName

End If

End If

Dim filestream As Stream
filestream = File.OpenWrite(SaveFileName)

While (True)

thisRead = networkStream.Read(dataByte, _
0, blockSize)
If thisRead = 0 Then Exit While
filestream.Write(dataByte, 0, blockSize.ToString)

End While

filestream.Close()
End SyncLock
lbConnections.Items.Add("File Written")
handlerSocket = Nothing

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Opacity = 0
Dim IpHost As IPHostEntry
IpHost = Dns.GetHostByName(Dns.GetHostName())
Label1.Text = "IP Address Is " + _
IpHost.AddressList(0).ToString()
alSockets = New ArrayList
Dim thdListener As New Thread(New ThreadStart _
(AddressOf listenerThread))
thdListener.Start()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Opacity = 0
End Sub
End Class
AnswerRe: Remote TCP file Transferring Pin
Garth J Lancaster3-Aug-10 17:25
professionalGarth J Lancaster3-Aug-10 17:25 
Question[VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom3-Aug-10 9:43
The Mighty Atom3-Aug-10 9:43 
AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Eddy Vluggen3-Aug-10 10:51
professionalEddy Vluggen3-Aug-10 10:51 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom3-Aug-10 11:53
The Mighty Atom3-Aug-10 11:53 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn3-Aug-10 12:31
sitebuilderLuc Pattyn3-Aug-10 12:31 
GeneralRe: [VB10] Check which ListBox items are selected and which are not [modified] Pin
The Mighty Atom3-Aug-10 13:01
The Mighty Atom3-Aug-10 13:01 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 7:14
The Mighty Atom4-Aug-10 7:14 
AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 8:12
sitebuilderLuc Pattyn4-Aug-10 8:12 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 8:46
The Mighty Atom4-Aug-10 8:46 
AnswerRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 9:25
sitebuilderLuc Pattyn4-Aug-10 9:25 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
The Mighty Atom4-Aug-10 9:45
The Mighty Atom4-Aug-10 9:45 
GeneralRe: [VB10] Check which ListBox items are selected and which are not Pin
Luc Pattyn4-Aug-10 11:42
sitebuilderLuc Pattyn4-Aug-10 11:42 
QuestionInput data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang2-Aug-10 12:03
Andraw Tang2-Aug-10 12:03 
AnswerRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Eddy Vluggen3-Aug-10 10:55
professionalEddy Vluggen3-Aug-10 10:55 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang4-Aug-10 3:49
Andraw Tang4-Aug-10 3:49 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Eddy Vluggen4-Aug-10 4:21
professionalEddy Vluggen4-Aug-10 4:21 
GeneralRe: Input data set changed dynamically according to option selection in VB.net 2005 Pin
Andraw Tang4-Aug-10 4:39
Andraw Tang4-Aug-10 4:39 

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.