Click here to Skip to main content
15,889,595 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Question"No to all" dialog result in Vb.net Pin
Member 203794320-Dec-07 22:19
Member 203794320-Dec-07 22:19 
GeneralRe: "No to all" dialog result in Vb.net Pin
Nilesh Hapse20-Dec-07 23:01
Nilesh Hapse20-Dec-07 23:01 
GeneralProblem in generating report in .NET Pin
Member 305788720-Dec-07 20:50
Member 305788720-Dec-07 20:50 
GeneralRe: Problem in generating report in .NET Pin
CKnig20-Dec-07 21:21
CKnig20-Dec-07 21:21 
GeneralRe: Problem in generating report in .NET Pin
Member 305788721-Dec-07 2:08
Member 305788721-Dec-07 2:08 
GeneralProblem with previleges with fileInfo/directoryInfo objects for moving a file Pin
SB 20-Dec-07 20:38
SB 20-Dec-07 20:38 
GeneralRe: Problem with previleges with fileInfo/directoryInfo objects for moving a file Pin
Dave Kreskowiak21-Dec-07 1:52
mveDave Kreskowiak21-Dec-07 1:52 
QuestionVB.NET P2P application? Pin
Benny_Lava20-Dec-07 20:16
Benny_Lava20-Dec-07 20:16 
Hi,

As the title says I need an code sample for direct connection between two devices (computers, or something else( in this case windows CE device)) when one of them connects to the other it directly sends some file (over the internet, using IP address and port) I have tried using TcpClient and tcpListener But I can't get it to work. my code:

The function that listens for a connection:

Const portNumber As Integer = 8000
Dim tcpListener As New TcpListener(portNumber)

tcpListener.Start()
Console.WriteLine("Waiting for connection...")
Try
'Accept the pending client connection and return a Tcplient initialized for communication.
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient
Console.WriteLine("Connection accepted.")
' Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
' Read the stream into a byte array
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client to the console.
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Client sent: " + clientdata))
Dim responseString As String = "Connected to server."
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Console.WriteLine(("Message Sent /> : " + responseString))
'Any communication with the remote client using the TcpClient can go here.
'Close TcpListener and TcpClient.
tcpClient.Close()
tcpListener.Stop()
Console.WriteLine("exit")
Catch e As Exception
Console.WriteLine(e.ToString())
End Try


The function that connects to the other device and sends the file:


Dim tcp As New System.Net.Sockets.TcpClient()

tcp.Connect(Me.tcpIPAdresa, Me.brojPorta)
Dim nStream As NetworkStream = tcp.GetStream
If nStream.CanRead And nStream.CanWrite Then
Dim sendBytes() As Byte = Encoding.ASCII.GetBytes("microstar")
nStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(tcp.ReceiveBufferSize) As Byte
nStream.Read(bytes, 0, CInt(tcp.ReceiveBufferSize))

Return True

Else
If Not nStream.CanRead Then
MsgBox("error cannot write")
tcp.Close()
Return False
Else
If Not nStream.CanWrite Then
MsgBox("error: cannot read data from the stream")
tcp.Close()
Return False
End If
End If
End If


Any ideas, code samples, anything.

Help greatly appreciated!
AnswerRe: VB.NET P2P application? Pin
CKnig20-Dec-07 21:28
CKnig20-Dec-07 21:28 
QuestionWindow Form application's user access control Pin
tellytub20-Dec-07 16:06
tellytub20-Dec-07 16:06 
QuestionFind DLL without specifying file path of Lib Pin
bj9308120-Dec-07 13:47
bj9308120-Dec-07 13:47 
GeneralRe: Find DLL without specifying file path of Lib Pin
Christian Graus20-Dec-07 14:18
protectorChristian Graus20-Dec-07 14:18 
QuestionRe: Find DLL without specifying file path of Lib Pin
bj9308120-Dec-07 18:03
bj9308120-Dec-07 18:03 
GeneralRe: Find DLL without specifying file path of Lib Pin
Christian Graus20-Dec-07 18:24
protectorChristian Graus20-Dec-07 18:24 
Generaltextbox validation Pin
hassanasp20-Dec-07 12:34
hassanasp20-Dec-07 12:34 
GeneralRe: textbox validation Pin
Christian Graus20-Dec-07 14:22
protectorChristian Graus20-Dec-07 14:22 
GeneralRe: textbox validation Pin
Paul Conrad22-Dec-07 13:06
professionalPaul Conrad22-Dec-07 13:06 
QuestionHow to connect to a ODBC database in c# or visual basic? Pin
mcirosoftmohan20-Dec-07 9:37
mcirosoftmohan20-Dec-07 9:37 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
Christian Graus20-Dec-07 9:48
protectorChristian Graus20-Dec-07 9:48 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
mcirosoftmohan20-Dec-07 10:06
mcirosoftmohan20-Dec-07 10:06 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
Christian Graus20-Dec-07 11:03
protectorChristian Graus20-Dec-07 11:03 
GeneralRe: How to connect to a ODBC database in c# or visual basic? Pin
GuyThiebaut21-Dec-07 6:05
professionalGuyThiebaut21-Dec-07 6:05 
QuestionConcurrency exceptions with only one user? Pin
craigmg7820-Dec-07 5:10
craigmg7820-Dec-07 5:10 
GeneralRe: Concurrency exceptions with only one user? [modified] Pin
Dave Kreskowiak20-Dec-07 7:36
mveDave Kreskowiak20-Dec-07 7:36 
GeneralRe: Concurrency exceptions with only one user? Pin
craigmg7820-Dec-07 8:10
craigmg7820-Dec-07 8:10 

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.