Client Server programming with the Winsock.dll
Posted
by Chris Aliotta
on January 29th, 2004

The attached sample (datasender.exe) should have at least two instances running - one to be the server and one as the client. You can then 'listen' as the server and 'connect' as the client to send data between the two.
Here are some samples of the code:
SocketNum = socket(AF_INET, SOCK_STREAM, 0)
If SocketNum < 1 then
Exit Sub
End If
SocketBuffer.sin_family = AF_INET
SocketBuffer.sin_port = htons(12310) 'port
SocketBuffer.sin_addr = 0
SocketBuffer.sin_zero = string$(8, 0)
X = bind(SocketNum, SocketBuffer, sockaddr_size)
If X <> 0 then
X = WSACleanup()
MsgBox "Failed to bind"
Exit Sub
End If
numListen = 2
X = listen(byval SocketNum, byval numListen)
X = WSAAsyncSelect(SocketNum, ReceiveWindow.hWnd, _
byval &H202, byval FD_CONNECT Or FD_ACCEPT)
This code specifies the port in which the application should listen on, the socket number, and the type of connection.
RC = SendData(SocketNum, "Your string") 'Sends data to
'the client/server
>- Use this to send data.
SocketBuffer.sin_family = AF_INET
SocketBuffer.sin_port = htons(12310)
SocketBuffer.sin_addr = IPAddr
SocketBuffer.sin_zero = string$(8, 0)
RC = connect(SocketNum, SocketBuffer, len(SocketBuffer))
- Designates a port, and IP address for the client and connects to the server.
It's somewhat complicated, but I hope the example I have provided helps. HAVE FUN!

Comments
how to track the no of bytes downloaded by the clients over a network?
Posted by Legacy on 02/03/2004 12:00amOriginally posted by: Himansu
hi,
i have a lan which consists of a windows 2000 server and all the clients have a static IP address. i want to keep a track of all the packets that the client is downloading from the internet...
is there already a tool that does this?
if i wanna develop my own s/w throught vb... do i have to do it through socket programming?
thanks in adv...
Replythanks thanks thanks...perfect !!!
Posted by Legacy on 10/17/2003 12:00amOriginally posted by: JANG JUN-YEONG
..
Reply
Need to send data from one to another computer by WINSOCK
Posted by Legacy on 10/14/2003 12:00amOriginally posted by: Alamdar
-
ReplySend data to other computer which is remotely located thru VB
Posted by kartiknath on 05/22/2006 09:20amcud anybody help me out how to send data from 1 computer to another computer.. remotely located. thru VB application and the database is MS. Access.
Replyget the other machine into a LAN
Posted by Legacy on 07/24/2003 12:00amOriginally posted by: sajal
hello
Replycan any body tell me how can i get the address of other machine into a lan.
Problems
Posted by Legacy on 07/17/2003 12:00amOriginally posted by: Ady B.
I used the socket code into one of my projects and I have some strange problem. I couldn't find it.
Here it is what it happens:
If I run the application in debug mode (from VB 6.0) it is working perfect. The problems appears only when I run the exe file. When I connect to server (I use the client application), the connection succedes, but after that the application crash with a system error. I use a timer that send from time to time something to server. This timer is set only if I get a valid connection to server. But I gues the problem is there, after the connection in the timer procedure.
ReplyCan someone, please, help me somehow? Any idea?
thanks
Posted by Legacy on 04/16/2003 12:00amOriginally posted by: socket
You are the man!
Reply
how does this work?
Posted by Legacy on 01/19/2003 12:00amOriginally posted by: bryan canlas
ReplyGet IP Address
Posted by Legacy on 10/30/2002 12:00amOriginally posted by: shilpa
Replysocket programming
Posted by Legacy on 07/24/2002 12:00amOriginally posted by: kavitha
ReplyHelp
Posted by Legacy on 06/09/2002 12:00amOriginally posted by: Meg@deth
I tried to use WinSock.OCX to create a chat program client/server.
There are multiple clients connecting to a cenral server.
This worked fine on a local network, but when ppl tried to connect remotely to the server they could not connect.
Is this just a bug with Winsock.OCX?
I looked at this example code.....quite a bit more long winded them using the OCX, lots of rewriting on my part
(:_O(
however your example only allows a single client to connect to a server.
How can I achieve the multiple clients to a server connection using a Winsock.dll?
Any ideas?
ReplyLoading, Please Wait ...