Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27472

The IAsyncResult was not returend from corresponding asychnonous method on this class

$
0
0
The IAsyncResult was not returend from corresponding asychnonous method on this class.

Why do I get this exception?... I think everything's alright on my code. thanks

VB Code:
  1. Imports MapleLib.PacketLib
  2. Imports System.Threading
  3. Imports System.Net.Sockets
  4.  
  5. Public Class InterceptedLinkedClient
  6.  
  7.     Private Block As Boolean = False
  8.     Private CharID As Integer = -1
  9.     Private Connected As Boolean = True
  10.     Private GotEncryption As Boolean = False
  11.     Private inSession As Session
  12.     Private Mutex As Mutex = New Mutex
  13.     Private Mutex2 As Mutex = New Mutex
  14.     Private outSession As Session
  15.     Private Port As UShort
  16.  
  17.     Public Sub New(pInside As Session, pIP As String, pPort As UShort)
  18.         Port = pPort
  19.         ' Log("New linked client to " & pIP & ".")
  20.         inSession = pInside
  21.  
  22.  
  23.         AddHandler pInside.OnPacketReceived, AddressOf Inside_OnPacketRecived
  24.         AddHandler pInside.OnClientDisconnected, AddressOf Inside_OnClientDisconnected
  25.         pInside.WaitForData()
  26.  
  27.  
  28.         ConnectOut(pIP, pPort)
  29.         ' Log("Connecting out to port " & pPort & ".")
  30.     End Sub
  31.  
  32.     Private Sub ConnectOut(IP As String, Port As Integer)
  33.         Try
  34.             Dim State As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  35.             State.BeginConnect(IP, Port, New AsyncCallback(AddressOf OnOutConnectCallback), State)
  36.         Catch ex As Exception
  37.             OutSession_OnClientDisconnected(Nothing)
  38.         End Try
  39.     End Sub
  40.  
  41.     Private Sub Inside_OnClientDisconnected(pSession As Session)
  42.         If outSession IsNot Nothing Then
  43.             outSession.Socket.Shutdown(SocketShutdown.Both)
  44.         End If
  45.  
  46.         Connected = False
  47.     End Sub
  48.  
  49.     Private Sub Inside_OnPacketRecived(pPacket As Byte())
  50.         If Connected AndAlso Not Block Then
  51.             Mutex.WaitOne()
  52.             Try
  53.                 If BitConverter.ToInt16(pPacket, 0) = 12 Then
  54.                     CharID = BitConverter.ToInt32(pPacket, 2)
  55.                 End If
  56.  
  57.                 MessageBox.Show(pPacket.ToString)
  58.                 outSession.SendPacket(pPacket)
  59.             Finally
  60.                 Mutex.ReleaseMutex()
  61.             End Try
  62.         End If
  63.     End Sub
  64.  
  65.     Private Sub OnOutConnectCallBack(AR As IAsyncResult)
  66.         Dim AsyncState As Socket = CType(AR.AsyncState, Socket)
  67.         Try
  68.             AsyncState.EndAccept(AR)
  69.         Catch ex As Exception
  70.             MessageBox.Show(ex.Message)
  71.             Connected = False
  72.             inSession.Socket.Shutdown(SocketShutdown.Both)
  73.             Return
  74.         End Try
  75.  
  76.  
  77.         If outSession IsNot Nothing Then
  78.             outSession.Socket.Close()
  79.             outSession.Connected = False
  80.         End If
  81.  
  82.  
  83.         Dim mSession As Session = New Session(AsyncState, SessionType.CLIENT_TO_SERVER)
  84.         outSession = mSession
  85.         AddHandler outSession.OnInitPacketReceived, AddressOf OutSession_OnInitPacketReceived
  86.         AddHandler outSession.OnPacketReceived, AddressOf OutSession_OnPacketREcieved
  87.         AddHandler outSession.OnClientDisconnected, AddressOf OutSession_OnClientDisconnected
  88.         mSession.WaitForDataNoEncryption()
  89.     End Sub
  90.  
  91.     Private Sub OutSession_OnClientDisconnected(pSession As Session)
  92.         If Not Block Then
  93.             inSession.Socket.Shutdown(SocketShutdown.Both)
  94.             'Log("Out disconnected (" & Port & ").")
  95.             Connected = False
  96.         End If
  97.     End Sub
  98.  
  99.     Private Sub OutSession_OnInitPacketReceived(pVersion As Short, pServerIdentifier As Byte, pStr As String)
  100.         'MessageBox.Show("Version: " & pVersion & ", Locale: " & pServerIdentifier + 1 & ".")
  101.         MessageBox.Show("Version: " & pVersion & ", Locale: " & pServerIdentifier & " ( +1 ).")
  102.         SendHandshake(pVersion, pServerIdentifier + 1, "1")
  103.     End Sub
  104.  
  105.     Private Sub OutSession_OnPacketREcieved(pPacket As Byte())
  106.         If GotEncryption AndAlso Connected Then
  107.             Mutex2.WaitOne()
  108.             Try
  109.                 MessageBox.Show(pPacket.ToString)
  110.                 inSession.SendPacket(pPacket)
  111.             Finally
  112.                 Mutex2.ReleaseMutex()
  113.             End Try
  114.         End If
  115.     End Sub
  116.  
  117.     Private Sub SendHandshake(pVersion As Short, pServerIdentifier As Byte, pStr As String)
  118.         Dim rnd As Random = New Random()
  119.         Dim RecvIV As MapleLib.MapleCryptoLib.MapleCrypto
  120.         Dim SendIV As MapleLib.MapleCryptoLib.MapleCrypto
  121.         RecvIV = New MapleLib.MapleCryptoLib.MapleCrypto(BitConverter.GetBytes(rnd.Next()), pVersion)
  122.         SendIV = New MapleLib.MapleCryptoLib.MapleCrypto(BitConverter.GetBytes(rnd.Next()), pVersion)
  123.  
  124.         Dim Packet As PacketWriter = New PacketWriter
  125.         Packet.WriteShort(13)
  126.         Packet.WriteShort(pVersion)
  127.         Packet.WriteMapleString("1")
  128.         Packet.WriteBytes(RecvIV.IV)
  129.         Packet.WriteBytes(SendIV.IV)
  130.         Packet.WriteByte(pServerIdentifier)
  131.         GotEncryption = True
  132.         inSession.SendRawPacket(Packet.ToArray)
  133.         'MessageBox.Show(Packet.ToArray.ToString)
  134.  
  135.         'Packet.WriteShort(13 + pStr.Length)
  136.         'Packet.WriteShort(pVersion)
  137.         'Packet.WriteMapleString(pStr)
  138.         'Dim Buffer As Byte() = New Byte(4) {}
  139.         'Dim Buffer2 As Byte() = New Byte(4) {}
  140.         'Dim Random As Random = New Random
  141.         'Random.NextBytes(Buffer)
  142.         'Random.NextBytes(Buffer2)
  143.         'inSession.RIV = New MapleLib.MapleCryptoLib.MapleCrypto(Buffer, pVersion)
  144.         'inSession.SIV = New MapleLib.MapleCryptoLib.MapleCrypto(Buffer2, pVersion)
  145.         'Packet.WriteBytes(Buffer)
  146.         'Packet.WriteBytes(Buffer2)
  147.         'Packet.WriteByte(pServerIdentifier)
  148.         'GotEncryption = True
  149.         'inSession.SendRawPacket(Packet.ToArray)
  150.     End Sub
  151.  
  152.     Public Sub Log(Message As String)
  153.         MessageBox.Show(Message)
  154.     End Sub
  155.  
  156. End Class

Viewing all articles
Browse latest Browse all 27472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>