VB Sockets project with eVB and VB6
페이지 정보
작성자
본문
Following up on my last adventure into the dark world of 'sockets' programming, I decided there must be a better way than the winsock control. GUI3000, my commercial software uses the sockets API, and this was really the way I wanted to go in eVB, but lack of support for UDT's, and the fact that the copymemory API is much used in VB sockets persuaded me against this. I thought there was a light at the end of the tunnel, when I read in the help file, that the Winsock control returned a socket handle for use in further calls. Alas, the light was only a train heading towards me, as I could not get this to work.
So once again, dusting off and donning the thinking cap I set to work. I decided to delve into the twilight zone of eVC, and write a wrapper for the sockets API callable from eVB. This article is the result of my labours, and contains the eVB and VB code to write a 'mickey-mouse' client server application WITHOUT the use of Winsock.ocx, or a safety net.
The project consists of a client process, written in eVB, and a server process, written in VB6. The server process simply accepts a connection from the client, accepts data, and sends it back. Both projects and the dll(s) are available for download.
First we need to declare the dll calls used by the program. I have tried to use the same names as the sockets API calls, prefixed by Ce.
Option Explicit
Declare Function CeWSAStartup _
Lib "CeSockets.dll" _
(vreq As Integer, ByVal debug_mode As Integer) _
As Integer
Declare Function CeSocket _
Lib "CeSockets.dll" _
() As Integer
Declare Function CeConnect _
Lib "CeSockets.dll" _
(ByVal isocket As Integer, _
ByVal iport As Integer, _
ByVal Shost As String) As Integer
Declare Function Cesend Lib "CeSockets.dll" _
(ByVal isocket As Integer, _
ByVal sbuff As String, _
ByVal ilen As Integer, _
ByVal iflags As Integer) _
As Integer
Declare Function Cerecv Lib "CeSockets.dll" _
(ByVal isocket As Integer, _
ByVal rbuff As String, _
ByVal ilen As Integer, _
ByVal iflags As Integer) _
As Integer
Declare Function CeGetIpAddress Lib _
"CeSockets.dll" (ByVal shostname As String, _
ByVal shostip As String) As Integer
Declare Function Cegethostbyaddr _
Lib "CeSockets.dll" _
(ByVal shostip As String, _
ByVal shostname As String) As Integer
Declare Function Cegetpeername Lib _
"CeSockets.dll" (ByVal isock As Integer, _
ByVal Shost As String) As Integer
Declare Function Cegethostname Lib _
"CeSockets.dll" (ByVal Shost As String) _
As Integer
Declare Function Ceclosesocket Lib _
"CeSockets.dll" (ByVal isocket As Integer) _
As Integer
Declare Function CeWSACleanup Lib _
"CeSockets.dll" () As Integer
Private hostname As String
Private hostip As String
Private iret As Integer
Private isocket As Integer
Private iport As Integer
Private sbuff As String
Private rbuff As String
Private ivreq As Integer
We then need to design a form, to allow us to connect, send and recv data.
[이 게시물은 오원장님에 의해 2013-02-28 16:42:18 오피스팁에서 이동 됨]
관련링크
댓글목록
등록된 댓글이 없습니다.