This topic is now archived and is closed to further replies.



Recommended Posts

Where is a good tutorial for using Winsock for a Client/Server chat/data application? I am trying to make a game of mine multiplayer. Also, why cant I do If (Winsock1.state = whatever). It tells me I cannot use Winsock1.state as a condition. Also, how can I test my application? If I run the server app and the client app at the same time, what IP should I use? The IP my router assigns to me? or "localhost" or something? Any help you can give me on Winsock would be appreciated.

Share this post

Link to post
Share on other sites
I have things set up now, here is server
Private Sub Form_Load()
'' Set the LocalPort property to an integer.
'' Then invoke the Listen method.
tcpServer.LocalPort = 1007
End Sub

Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
'' Check if the control''s State is closed. If not,
'' close the connection before accepting the new
'' connection.
''If tcpServer.State <> sckClosed Then tcpServer.Close()
'' Accept the request with the requestID
'' parameter.
Label1.Text = "Awaiting Connection..."
Label1.text = "Connected"
End Sub

Private Sub txtSendData_Change()
'' The TextBox control named txtSendData
'' contains the data to be sent. Whenever the user
'' types into the textbox, the string is sent
'' using the SendData method.
End Sub

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
'' Declare a variable for the incoming data.
'' Invoke the GetData method and set the Text
'' property of a TextBox named txtOutput to
'' the data.
Dim strData As String
txtOutput.Text = strData
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frmClientForm.Show() '' Show the client form.
frmClientForm.Visible = True
End Sub

Here is client
Private Sub Form_Load()
'' The name of the Winsock control is tcpClient.
'' Note: to specify a remote host, you can use
'' either the IP address (ex: "") or
'' the computer''s "friendly" name, as shown here.
tcpClient.RemoteHost = ""
tcpClient.RemotePort = 1007
End Sub

Private Sub txtSend_Change()
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
txtOutput.Text = strData
End Sub

Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
tcpClient.RemoteHost = txtIP.Text
'' Invoke the Connect method to initiate a connection.
Label1.Text = "Connecting..."
tcpClient.Connect(tcpClient.RemoteHost, tcpClient.RemotePort)
Label1.Text = "Connected"
End Sub

I am behind a router. The IP my router assigns me I''ll call for now. So I tell the client to connect like so

But my server app never receives that request. The label never changes at all, letting me know a request was made. How can I get the clients request to be heard by the server?

Share this post

Link to post
Share on other sites
You might try ""

Also, if you ever get your client and server up and running I'd be interested in looking at some VB source (as I haven't worked in VB in years and have worked with winsock in C++ only recently). Cheers.

[edited by - woodsman on January 25, 2004 7:28:01 PM]

Share this post

Link to post
Share on other sites
On my site I have a network module (C++) with a simple console chat-thingy ontop of it. In the header file, the ackknowledgements section, I refer to a tutorial from RedKlyde on, which I mainly used as a source.

The module can be downed at:

The list of sources:

redKlyde - TCP tutorial @



Testing your application locally can be done using the IP-address, which is the internal loopback address, also know as LOCALHOST. Latency can not be tested with this.

Share this post

Link to post
Share on other sites
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.

Check out this link for information on winsock.

Check out my website for more links to software development.


Share this post

Link to post
Share on other sites