LazyDreamy » Computer/Programming
.NET Socket Programming (for data arriving event)
드림 | 2010/03/07 23:09
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text' State object for receiving data from remote device.
Public Class StateObject
' Client socket.
Public workSocket As Socket = Nothing
' Size of receive buffer.
Public Const BufferSize As Integer = 256
' Receive buffer.
Public buffer(BufferSize) As Byte
' Received data string.
Public sb As New StringBuilder
End Class 'StateObjectPublic Class AsynchronousClient
' The port number for the remote device.
Private Const port As Integer = 11000' ManualResetEvent instances signal completion.
Private Shared connectDone As New ManualResetEvent(False)
Private Shared sendDone As New ManualResetEvent(False)
Private Shared receiveDone As New ManualResetEvent(False)' The response from the remote device.
Private Shared response As String = String.EmptyPublic Shared Sub Main()
' Establish the remote endpoint for the socket.
' For this example use local machine.
Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName())
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, port)' Create a TCP/IP socket.
Dim client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)' Connect to the remote endpoint.
client.BeginConnect(remoteEP, New AsyncCallback(AddressOf ConnectCallback), client)' Wait for connect.
connectDone.WaitOne()' Send test data to the remote device.
Send(client, "This is a test<EOF>")
sendDone.WaitOne()' Receive the response from the remote device.
Receive(client)
receiveDone.WaitOne()' Write the response to the console.
Console.WriteLine("Response received : {0}", response)' Release the socket.
client.Shutdown(SocketShutdown.Both)
client.Close()
End Sub 'MainPrivate Shared Sub ConnectCallback(ByVal ar As IAsyncResult)
' Retrieve the socket from the state object.
Dim client As Socket = CType(ar.AsyncState, Socket)' Complete the connection.
client.EndConnect(ar)Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString())
' Signal that the connection has been made.
connectDone.Set()
End Sub 'ConnectCallbackPrivate Shared Sub Receive(ByVal client As Socket)
' Create the state object.
Dim state As New StateObject
state.workSocket = client' Begin receiving the data from the remote device.
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReceiveCallback), state)
End Sub 'ReceivePrivate Shared Sub ReceiveCallback(ByVal ar As IAsyncResult)
' Retrieve the state object and the client socket
' from the asynchronous state object.
Dim state As StateObject = CType(ar.AsyncState, StateObject)
Dim client As Socket = state.workSocket' Read data from the remote device.
Dim bytesRead As Integer = client.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))' Get the rest of the data.
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReceiveCallback), state)
Else
' All the data has arrived; put it in response.
If state.sb.Length > 1 Then
response = state.sb.ToString()
End If
' Signal that all bytes have been received.
receiveDone.Set()
End If
End Sub 'ReceiveCallbackPrivate Shared Sub Send(ByVal client As Socket, ByVal data As String)
' Convert the string data to byte data using ASCII encoding.
Dim byteData As Byte() = Encoding.ASCII.GetBytes(data)' Begin sending the data to the remote device.
client.BeginSend(byteData, 0, byteData.Length, 0, New AsyncCallback(AddressOf SendCallback), client)
End Sub 'SendPrivate Shared Sub SendCallback(ByVal ar As IAsyncResult)
' Retrieve the socket from the state object.
Dim client As Socket = CType(ar.AsyncState, Socket)' Complete sending the data to the remote device.
Dim bytesSent As Integer = client.EndSend(ar)
Console.WriteLine("Sent {0} bytes to server.", bytesSent)' Signal that all bytes have been sent.
sendDone.Set()
End Sub 'SendCallback
End Class 'AsynchronousClient
출처 : http://msdn.microsoft.com/en-us/library/bew39x2a.aspx
winsock 을 강제로 사용하지 않고, .net 내장 함수를 사용하려고 찾다 보니 소켓 이벤트 형태를 지원한다.
LazyDreamy » Computer/Programming
Windows 7 mscomm32.ocx , mswinsck.ocx 사용하기
드림 | 2010/02/27 10:09
뭐..;; 하다보면 아직 구버전으로 개발된 것들이 있어서 테스트 하기위해 돌려보면 ocx 파일 로딩 에러가 납니다.
windows 7 에서는 해당 파일을 구해서 windows\sysWOW64 에 넣고 등록하면 정상적으로 동작합니다.
간단히 정리하면
1. ocx 파일을 windows\sysWOW64 에 복사
2. regsvr32 windows\sysWOW64\ocx파일명
그외에 필요하면 dll 파일은 system32 에 두면 됩니다.
추가 -
sysWOW64 가 어떤 부분을 지원하는 것인가 찾아보니까
64비트 운영체제의 경우 system32 에 64비트 라이브러리가 들어가고 32비트 라이브러리는 sysWOW64 에 위치한다고합니다.
아마 운영체제가 32비트 일 경우 ocx 파일의 위치와 로딩은 system32 에서 하는 것이 맞다고 생각됩니다.
해당 부분은 windows7 64비트를 기준으로 작성되었습니다.
참고 url : http://www.sevenforums.com/drivers/47248-mscomm32.html
dolphin - gamecube and wii emulator
드림 | 2010/02/24 23:11
트랙백 없음 | 댓글 3개
트랙백+댓글 | 트랙백 | 댓글
-
Comment by 샨 at 2010/02/25 04:46 / Permalink / Reply / Modify/Delete
우리 연아 나오나여?
-
Comment by 뚜르 at 2010/02/25 09:01 / Permalink / Reply / Modify/Delete
마르코는 안나오나염?
-
Comment by 드림 at 2010/03/01 22:49 / Permalink / Reply / Modify/Delete
마리오랑 소닉이 나와염 =3=3=33
-
Write your comment






CRC.C


VB6KO.dll














