Archived

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

LoopUniverse

WINSOCK HELP

Recommended Posts

LoopUniverse    122
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
LoopUniverse    122
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
tcpServer.Listen()
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..."
tcpServer.Close()
tcpServer.Accept(requestID)
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.
tcpServer.SendData(txtSendData.Text)
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
tcpServer.GetData(strData)
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: "121.111.1.1") or
'' the computer''s "friendly" name, as shown here.
tcpClient.RemoteHost = "111.111.1.111"
tcpClient.RemotePort = 1007
End Sub

Private Sub txtSend_Change()
tcpClient.SendData(txtSend.Text)
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpClient.GetData(strData)
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.Close()
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 111.111.1.111 for now. So I tell the client to connect like so
tcpClient.connect("111.111.1.111",1007)

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
Woodsman    426
You might try "127.0.0.1"

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
Structural    328
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 gameTutorials.com, which I mainly used as a source.

The module can be downed at: http://www.structweb.com/?show=project&project=9

The list of sources:

redKlyde - TCP tutorial @ www.gametutorials.com

UNKNOWN - http://www.district86.k12.il.us/central/activities/computerclub/Tutorials/Winsock/Lesson4.htm
http://www.district86.k12.il.us/central/activities/computerclub/Tutorials/Winsock/Lesson5.htm

MSDN - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcewinsk/html/_wcecomm_Developing_a_Winsock_Application.asp



Testing your application locally can be done using the IP-address 127.0.0.1, 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
kuphryn    210
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.

Check out this link for information on winsock.

http://www.tangentsoft.net/wskfaq/

Check out my website for more links to software development.

http://www.dslextreme.com/users/kuphryn/links.html

Kuphryn

Share this post


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

An excellent text.

Share this post


Link to post
Share on other sites
Nice Coder    366
I may have advice to offer,
Try to use somebody elses *Working winsock program* then change it until it suits your needs (winsock does not like me )

Nice coder

Share this post


Link to post
Share on other sites