LazyDreamy

관리자 | 글쓰기

LazyDreamy » Computer/Programming

C CRC16, CRC32, CRC-CCITT

드림 | 2010/03/08 22:48


출처 : 볼랜드 포럼 (http://turboc.borlandforum.com/impboard/impboard.dll?action=read&db=cpp_res&no=70)

http://forum.falinux.com/zbxe/?mid=lecture_tip&document_srl=406152&sort_index=readed_count&order_type=desc

http://www.lammertbies.nl/comm/info/crc-calculation.html
2010/03/08 22:48 2010/03/08 22:48


(go to top)

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 'StateObject

Public 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.Empty

    Public 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 'Main

    Private 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 'ConnectCallback

    Private 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 'Receive

    Private 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 'ReceiveCallback

    Private 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 'Send

    Private 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 내장 함수를 사용하려고 찾다 보니 소켓 이벤트 형태를 지원한다.

2010/03/07 23:09 2010/03/07 23:09


(go to top)

LazyDreamy » Computer/Programming

BCB W8058 Cannot create pre-compiled header

드림 | 2010/03/03 22:33

2010-03-03 오후 10-25-12

 

해결

#include <vcl.h>
#pragma hdrstop

#pragma hdrstop
#include <vcl.h>

로 순서를 수정

 

2010-03-03 오후 10-25-56

 

성공.. tpasyncpro 깔기 힘들다 –;

 

참고주소 : http://www.richelbilderbeek.nl/CppCompileWarningCannotCreatePreCompiledHeaderInitializedDataInHeader.htm

2010/03/03 22:33 2010/03/03 22:33


(go to top)

LazyDreamy » Computer/Programming

Windows 7 mscomm32.ocx , mswinsck.ocx 사용하기

드림 | 2010/02/27 10:09

Windows 7에서부터는 VS6 버전과의 호환성 문제가 있습니다.

뭐..;; 하다보면 아직 구버전으로 개발된 것들이 있어서 테스트 하기위해 돌려보면 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
2010/02/27 10:09 2010/02/27 10:09


(go to top)

LazyDreamy » Diary

dolphin - gamecube and wii emulator

드림 | 2010/02/24 23:11

2010-02-24 오후 11-06-50

http://www.dolphin-emu.com/

wiimote 나 기타 패드까지 지원하고, 꽤 빨리 리비전이 올라오는 듯.

동물의 숲을 좀 편하게 할 방법을 찾다가 여기까지..;

2010/02/24 23:11 2010/02/24 23:11


(go to top)

◀ recent | 1 | 2 | 3 | 4 | 5 | ... 74 | previous ▶