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
Why do I get this exception?... I think everything's alright on my code. thanks
VB Code:
Imports MapleLib.PacketLib Imports System.Threading Imports System.Net.Sockets Public Class InterceptedLinkedClient Private Block As Boolean = False Private CharID As Integer = -1 Private Connected As Boolean = True Private GotEncryption As Boolean = False Private inSession As Session Private Mutex As Mutex = New Mutex Private Mutex2 As Mutex = New Mutex Private outSession As Session Private Port As UShort Public Sub New(pInside As Session, pIP As String, pPort As UShort) Port = pPort ' Log("New linked client to " & pIP & ".") inSession = pInside AddHandler pInside.OnPacketReceived, AddressOf Inside_OnPacketRecived AddHandler pInside.OnClientDisconnected, AddressOf Inside_OnClientDisconnected pInside.WaitForData() ConnectOut(pIP, pPort) ' Log("Connecting out to port " & pPort & ".") End Sub Private Sub ConnectOut(IP As String, Port As Integer) Try Dim State As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) State.BeginConnect(IP, Port, New AsyncCallback(AddressOf OnOutConnectCallback), State) Catch ex As Exception OutSession_OnClientDisconnected(Nothing) End Try End Sub Private Sub Inside_OnClientDisconnected(pSession As Session) If outSession IsNot Nothing Then outSession.Socket.Shutdown(SocketShutdown.Both) End If Connected = False End Sub Private Sub Inside_OnPacketRecived(pPacket As Byte()) If Connected AndAlso Not Block Then Mutex.WaitOne() Try If BitConverter.ToInt16(pPacket, 0) = 12 Then CharID = BitConverter.ToInt32(pPacket, 2) End If MessageBox.Show(pPacket.ToString) outSession.SendPacket(pPacket) Finally Mutex.ReleaseMutex() End Try End If End Sub Private Sub OnOutConnectCallBack(AR As IAsyncResult) Dim AsyncState As Socket = CType(AR.AsyncState, Socket) Try AsyncState.EndAccept(AR) Catch ex As Exception MessageBox.Show(ex.Message) Connected = False inSession.Socket.Shutdown(SocketShutdown.Both) Return End Try If outSession IsNot Nothing Then outSession.Socket.Close() outSession.Connected = False End If Dim mSession As Session = New Session(AsyncState, SessionType.CLIENT_TO_SERVER) outSession = mSession AddHandler outSession.OnInitPacketReceived, AddressOf OutSession_OnInitPacketReceived AddHandler outSession.OnPacketReceived, AddressOf OutSession_OnPacketREcieved AddHandler outSession.OnClientDisconnected, AddressOf OutSession_OnClientDisconnected mSession.WaitForDataNoEncryption() End Sub Private Sub OutSession_OnClientDisconnected(pSession As Session) If Not Block Then inSession.Socket.Shutdown(SocketShutdown.Both) 'Log("Out disconnected (" & Port & ").") Connected = False End If End Sub Private Sub OutSession_OnInitPacketReceived(pVersion As Short, pServerIdentifier As Byte, pStr As String) 'MessageBox.Show("Version: " & pVersion & ", Locale: " & pServerIdentifier + 1 & ".") MessageBox.Show("Version: " & pVersion & ", Locale: " & pServerIdentifier & " ( +1 ).") SendHandshake(pVersion, pServerIdentifier + 1, "1") End Sub Private Sub OutSession_OnPacketREcieved(pPacket As Byte()) If GotEncryption AndAlso Connected Then Mutex2.WaitOne() Try MessageBox.Show(pPacket.ToString) inSession.SendPacket(pPacket) Finally Mutex2.ReleaseMutex() End Try End If End Sub Private Sub SendHandshake(pVersion As Short, pServerIdentifier As Byte, pStr As String) Dim rnd As Random = New Random() Dim RecvIV As MapleLib.MapleCryptoLib.MapleCrypto Dim SendIV As MapleLib.MapleCryptoLib.MapleCrypto RecvIV = New MapleLib.MapleCryptoLib.MapleCrypto(BitConverter.GetBytes(rnd.Next()), pVersion) SendIV = New MapleLib.MapleCryptoLib.MapleCrypto(BitConverter.GetBytes(rnd.Next()), pVersion) Dim Packet As PacketWriter = New PacketWriter Packet.WriteShort(13) Packet.WriteShort(pVersion) Packet.WriteMapleString("1") Packet.WriteBytes(RecvIV.IV) Packet.WriteBytes(SendIV.IV) Packet.WriteByte(pServerIdentifier) GotEncryption = True inSession.SendRawPacket(Packet.ToArray) 'MessageBox.Show(Packet.ToArray.ToString) 'Packet.WriteShort(13 + pStr.Length) 'Packet.WriteShort(pVersion) 'Packet.WriteMapleString(pStr) 'Dim Buffer As Byte() = New Byte(4) {} 'Dim Buffer2 As Byte() = New Byte(4) {} 'Dim Random As Random = New Random 'Random.NextBytes(Buffer) 'Random.NextBytes(Buffer2) 'inSession.RIV = New MapleLib.MapleCryptoLib.MapleCrypto(Buffer, pVersion) 'inSession.SIV = New MapleLib.MapleCryptoLib.MapleCrypto(Buffer2, pVersion) 'Packet.WriteBytes(Buffer) 'Packet.WriteBytes(Buffer2) 'Packet.WriteByte(pServerIdentifier) 'GotEncryption = True 'inSession.SendRawPacket(Packet.ToArray) End Sub Public Sub Log(Message As String) MessageBox.Show(Message) End Sub End Class