Click here to Skip to main content
15,902,447 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: UAC in Vista Pin
Christian Graus7-Aug-07 16:58
protectorChristian Graus7-Aug-07 16:58 
GeneralRe: UAC in Vista Pin
Kumaran21cen7-Aug-07 18:07
Kumaran21cen7-Aug-07 18:07 
GeneralRe: UAC in Vista Pin
Christian Graus7-Aug-07 19:14
protectorChristian Graus7-Aug-07 19:14 
GeneralRe: UAC in Vista Pin
Colin Angus Mackay8-Aug-07 0:38
Colin Angus Mackay8-Aug-07 0:38 
GeneralRe: UAC in Vista Pin
Dave Kreskowiak8-Aug-07 3:26
mveDave Kreskowiak8-Aug-07 3:26 
QuestionSimple Firewall Pin
VIP-CoMmAnDo7-Aug-07 14:42
VIP-CoMmAnDo7-Aug-07 14:42 
AnswerRe: Simple Firewall Pin
Dave Kreskowiak8-Aug-07 3:30
mveDave Kreskowiak8-Aug-07 3:30 
QuestionTCP-Connection between two Clients Pin
Andi Bar7-Aug-07 13:16
Andi Bar7-Aug-07 13:16 
for the first: i'm from germany so my english isn't very good. sorry.

ok, i want to create a network connection between two clients. that you know better what i want, think on a chat!

ok, thats the code of the microsoft dokumentation:

TCP-Listener
<br />
Imports System<br />
Imports System.IO<br />
Imports System.Net<br />
Imports System.Net.Sockets<br />
Imports System.Text<br />
Imports Microsoft.VisualBasic<br />
<br />
<br />
Class MyTcpListener<br />
<br />
    Public Shared Sub Main()<br />
<br />
   Dim server As TcpListener<br />
   server=nothing<br />
        Try<br />
            ' Set the TcpListener on port 13000.<br />
         Dim port As Int32 = 13000<br />
         Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")<br />
<br />
         server = New TcpListener(localAddr, port)<br />
         <br />
         ' Start listening for client requests.<br />
         server.Start()<br />
         <br />
         ' Buffer for reading data<br />
            Dim bytes(1024) As Byte<br />
            Dim data As String = Nothing<br />
         <br />
         ' Enter the listening loop.<br />
         While True<br />
            Console.Write("Waiting for a connection... ")<br />
            <br />
            ' Perform a blocking call to accept requests.<br />
            ' You could also user server.AcceptSocket() here.<br />
            Dim client As TcpClient = server.AcceptTcpClient()<br />
            Console.WriteLine("Connected!")<br />
            <br />
            data = Nothing<br />
            <br />
            ' Get a stream object for reading and writing<br />
            Dim stream As NetworkStream = client.GetStream()<br />
            <br />
            Dim i As Int32<br />
            <br />
            ' Loop to receive all the data sent by the client.<br />
            i = stream.Read(bytes, 0, bytes.Length)<br />
            While (i <> 0) <br />
               ' Translate data bytes to a ASCII string.<br />
               data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)<br />
                    Console.WriteLine("Received: {0}", data)<br />
               <br />
               ' Process the data sent by the client.<br />
               data = data.ToUpper()<br />
                    Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data)<br />
               <br />
               ' Send back a response.<br />
               stream.Write(msg, 0, msg.Length)<br />
                    Console.WriteLine("Sent: {0}", data)<br />
              <br />
               i = stream.Read(bytes, 0, bytes.Length)<br />
<br />
            End While<br />
            <br />
            ' Shutdown and end connection<br />
            client.Close()<br />
         End While<br />
      Catch e As SocketException<br />
         Console.WriteLine("SocketException: {0}", e)<br />
      Finally<br />
         server.Stop()<br />
      End Try<br />
      <br />
      Console.WriteLine(ControlChars.Cr + "Hit enter to continue....")<br />
      Console.Read()<br />
   End Sub 'Main<br />
<br />
End Class 'MyTcpListener <br />


TCP-Client
<br />
Shared Sub Connect(server As [String], message As [String])<br />
   Try<br />
      ' Create a TcpClient.<br />
      ' Note, for this client to work you need to have a TcpServer <br />
      ' connected to the same address as specified by the server, port<br />
      ' combination.<br />
      Dim port As Int32 = 13000<br />
      Dim client As New TcpClient(server, port)<br />
      <br />
      ' Translate the passed message into ASCII and store it as a Byte array.<br />
      Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)<br />
      <br />
      ' Get a client stream for reading and writing.<br />
      '  Stream stream = client.GetStream();<br />
      Dim stream As NetworkStream = client.GetStream()<br />
      <br />
      ' Send the message to the connected TcpServer. <br />
      stream.Write(data, 0, data.Length)<br />
      <br />
      Console.WriteLine("Sent: {0}", message)<br />
      <br />
      ' Receive the TcpServer.response.<br />
      ' Buffer to store the response bytes.<br />
      data = New [Byte](256) {}<br />
      <br />
      ' String to store the response ASCII representation.<br />
      Dim responseData As [String] = [String].Empty<br />
      <br />
      ' Read the first batch of the TcpServer response bytes.<br />
      Dim bytes As Int32 = stream.Read(data, 0, data.Length)<br />
      responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)<br />
      Console.WriteLine("Received: {0}", responseData)<br />
      <br />
      ' Close everything.<br />
      stream.Close()<br />
      client.Close()<br />
   Catch e As ArgumentNullException<br />
      Console.WriteLine("ArgumentNullException: {0}", e)<br />
   Catch e As SocketException<br />
      Console.WriteLine("SocketException: {0}", e)<br />
   End Try<br />
   <br />
   Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")<br />
   Console.Read()<br />
End Sub 'Connect<br />


questions:

1. What do i have to do now that this code works? (for exampe on my own PC, 127.0.0.1)
2. In which order do i have to call the subs of the two classes (TCP Listener and TCP Client)?
3. Which parameters must the sub of TCP-Client have? (i think the message-parameter can be choosed by random...any string. But i have problems with the server-parameter! What should i fill in there?)

Greetz
QuestionCall a control's click event Pin
x-Taka-x7-Aug-07 11:48
x-Taka-x7-Aug-07 11:48 
AnswerRe: Call a control's click event Pin
Christian Graus7-Aug-07 12:09
protectorChristian Graus7-Aug-07 12:09 
GeneralRe: Call a control's click event Pin
x-Taka-x11-Aug-07 0:16
x-Taka-x11-Aug-07 0:16 
AnswerSenthil's Reply for Call a control's click event Pin
Senthil S8-Aug-07 2:12
Senthil S8-Aug-07 2:12 
GeneralRe: Senthil's Reply for Call a control's click event Pin
x-Taka-x11-Aug-07 0:18
x-Taka-x11-Aug-07 0:18 
QuestionCalling a C ++ DLL from a VB 2005 application Pin
jyothim7-Aug-07 11:44
jyothim7-Aug-07 11:44 
AnswerRe: Calling a C ++ DLL from a VB 2005 application Pin
Christian Graus7-Aug-07 12:10
protectorChristian Graus7-Aug-07 12:10 
GeneralRe: Calling a C ++ DLL from a VB 2005 application Pin
jyothim8-Aug-07 3:13
jyothim8-Aug-07 3:13 
QuestionCystal Report Pin
Assaf827-Aug-07 10:31
Assaf827-Aug-07 10:31 
QuestionUser Authentication Pin
Lexi Phillips7-Aug-07 10:11
Lexi Phillips7-Aug-07 10:11 
AnswerRe: User Authentication Pin
Tom Deketelaere8-Aug-07 1:23
professionalTom Deketelaere8-Aug-07 1:23 
QuestionMaking sure a file really is there Pin
'Drew7-Aug-07 9:56
'Drew7-Aug-07 9:56 
AnswerRe: Making sure a file really is there Pin
The ANZAC7-Aug-07 10:41
The ANZAC7-Aug-07 10:41 
GeneralRe: Making sure a file really is there Pin
'Drew7-Aug-07 11:38
'Drew7-Aug-07 11:38 
GeneralRe: Making sure a file really is there Pin
Dave Kreskowiak7-Aug-07 12:28
mveDave Kreskowiak7-Aug-07 12:28 
GeneralRe: Making sure a file really is there Pin
'Drew7-Aug-07 12:51
'Drew7-Aug-07 12:51 
GeneralRe: Making sure a file really is there Pin
Dave Kreskowiak7-Aug-07 13:01
mveDave Kreskowiak7-Aug-07 13:01 

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.