vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Erstellen von dynamischen Kontextmen?s - wann immer Sie sie brauchen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: Sockets und Post 
Autor: rub
Datum: 11.10.06 14:29

Habs wohl doch noch nicht ganz.
Ich poste gerade noc mal alles
Die Problemstellen sind fett markiert.
Server Teil1
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
 
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles Button1.Click
        Call AsynchronousSocketListener.Main()
    End Sub
End Class
'-------------------------------
Public Class StateObject
    ' Client  socket.
    Public workSocket As Socket = Nothing
    ' Size of receive buffer.
    Public Const BufferSize As Integer = 1024
    ' Receive buffer.
    Public buffer(BufferSize) As Byte
    ' Received data string.
    Public sb As New StringBuilder
End Class
'-------------------------------
Public Class AsynchronousSocketListener
    ' Thread signal.
    Public Shared allDone As New ManualResetEvent(False)
    ' This server waits for a connection and then uses  asychronous operations 
    ' to
    ' accept the connection, get data from the connected client, 
    ' echo that data back to the connected client.
    ' It then disconnects from the client and waits for another client. 
    Public Shared Sub Main()
        ' Data buffer for incoming data.
        Dim bytes() As Byte = New [Byte](1023) {}
        ' Establish the local endpoint for the socket.
        Dim localEndPoint As New IPEndPoint(Net.IPAddress.Any, 3000)
        ' Create a TCP/IP socket.
        'Dim listener As New Socket(AddressFamily.InterNetwork, 
        ' SocketType.Stream, ProtocolType.Tcp)
        Dim listener As New Socket(AddressFamily.InterNetwork, _
          SocketType.Stream, ProtocolType.Tcp)
        ' Bind the socket to the local endpoint and listen for incoming 
        ' connections.
        listener.Bind(localEndPoint)
        listener.Listen(1000)
        While True
            ' Set the event to nonsignaled state.
            allDone.Reset()
            ' Start an asynchronous socket to listen for connections.
            listener.BeginAccept(New AsyncCallback(AddressOf AcceptCallback), _
              listener)
            ' Wait until a connection is made and processed before continuing.
            allDone.WaitOne()
        End While
    End Sub
 
    Public Shared Sub AcceptCallback(ByVal ar As IAsyncResult)
        ' Get the socket that handles the client request.
        Dim listener As Socket = CType(ar.AsyncState, Socket)
        ' End the operation.
        Dim handler As Socket = listener.EndAccept(ar)
        ' Create the state object for the async receive.
        Dim state As New StateObject
        state.workSocket = handler
        handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New _
          AsyncCallback(AddressOf ReadCallback), state)
    End Sub
 
    Public Shared Sub ReadCallback(ByVal ar As IAsyncResult)
        Dim content As String = String.Empty
        ' Retrieve the state object and the handler socket
        ' from the asynchronous state object.
        Dim state As StateObject = CType(ar.AsyncState, StateObject)
        Dim handler As Socket = state.workSocket
        ' Read data from the client socket. 
        Dim bytesRead As Integer = handler.EndReceive(ar)
        If bytesRead > 0 Then
            ' There  might be more data, so store the data received so far.
            state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, _
              bytesRead))
            content = state.sb.ToString()
            Send(handler)
        End If
    End Sub
...
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Sockets und Post3.863rub10.10.06 15:30
Der Client2.188rub10.10.06 15:30
Re: Sockets und Post2.246ModeratorDaveS10.10.06 15:39
Re: Sockets und Post2.168rub10.10.06 16:37
Re: Sockets und Post2.089ModeratorDaveS10.10.06 17:27
Re: Sockets und Post2.147SystemX11.10.06 10:11
Re: Sockets und Post2.044rub11.10.06 11:53
Re: Sockets und Post2.171rub11.10.06 14:29
Server Teil22.076rub11.10.06 14:29
Client2.197rub11.10.06 14:35
Re: Client1.992rub11.10.06 14:37
Re: Sockets und Post1.951rub11.10.06 15:12
Re: Sockets und Post2.329rub11.10.06 17:26
Re: Sockets und Post2.142ModeratorDaveS11.10.06 17:49
Re: Sockets und Post2.133rub12.10.06 10:17
Re: Sockets und Post2.061ModeratorDaveS12.10.06 10:29

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel