Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to pass variables over a lan

Posted on 1998-08-05
12
Medium Priority
?
221 Views
Last Modified: 2013-11-13
my friend and i want to learn to write a vb game (like tic tac toe) to run over our lan.  we have no idea how to start.  it seems like we would just need to be able to find another computer running the program, and then pass variables from one machine to the other.  could you help us do these two things, and maybe give some other tips/links?
     thanks
0
Comment
Question by:darink
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1467992
You have to use TCP/IP to pass data between computers. In VB, This can be done pretty easily using the Winsock control.
0
 

Author Comment

by:darink
ID: 1467993
can you say any more?
0
 

Author Comment

by:darink
ID: 1467994
can you say any more?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:MikeP090797
ID: 1467995
You place a winsock control on your form. You call Connect with the address of the remote machine. After you are connected, you can pass data using Send. You just have to come up with a format that will be easy to interpret. The winsock conrol is documented pretty well, but if you have any problems, just ask
0
 

Author Comment

by:darink
ID: 1467996
how can i keep from getting the address in use error?  we can connect, and pass data, but then, after we disconnect and try to connect again, we get that error.  we are disconnecting the first time and unloading before we exit.  help.
0
 
LVL 1

Accepted Solution

by:
jsuper earned 100 total points
ID: 1467997
When using the Winsock control,  try to connect as soon after the program starts as possible.   LEAVE the connection UP until the application ends.  If you disconnect you will not be able to reconnect without shutting down the application and restarting.   Once a connection has been established between the two jobs, the connection is pretty stable so you shouldn't have any problems with accidental disconnects.   Another way to go is to dynamically create a Winsock control in code.  I have built an entire class module with TCP/IP configuration screens around it that make the winsock very easy to use.  It also allows you to reset the connection without ending the application.  Try not to disconnect until the program ends and see if that solves your problem.  Otherwise send a comment back and I'll try to steer you in the right direction...   Good Luck.
0
 
LVL 1

Expert Comment

by:jsuper
ID: 1467998
Actually, Reject this answer because MikeP deserves the points.
0
 
LVL 14

Expert Comment

by:waty
ID: 1467999
Why don't you communicate between the two computers using files. The first computer could write to a file, and the other to another file. This is very easy to implement, the error handling will be easier than for TCP-IP or Winsock. And you could play with other computers based on same principle
0
 

Author Comment

by:darink
ID: 1468000
would maping network drives be easiest for that?

0
 
LVL 14

Expert Comment

by:waty
ID: 1468001
It is very easy to map a network drive under NT, here is the code :

Option Explicit

Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long

Const WN_Success = &H0
Const WN_Not_Supported = &H1
Const WN_Net_Error = &H2
Const WN_Bad_Pointer = &H4
Const WN_Bad_NetName = &H32
Const WN_Bad_Password = &H6
Const WN_Bad_Localname = &H33
Const WN_Access_Denied = &H7
Const WN_Out_Of_Memory = &HB
Const WN_Already_Connected = &H34

'-- Error number and message
Public ErrorNum         As Long
Public ErrorMsg         As String

Public rc               As Long

Private Const ERROR_NO_CONNECTION = 8
Private Const ERROR_NO_DISCONNECT = 9

Public Sub Connect(sDrive As String, sService As String, Optional sPassword As String = "")
   
   On Error GoTo Err_Connect
   Me.ErrorNum = 0
   Me.ErrorMsg = ""
   rc = WNetAddConnection(sService & Chr(0), sPassword & Chr(0), sDrive & Chr(0))
   If rc <> 0 Then GoTo Err_Connect
   
   Exit Sub

Err_Connect:
   Me.ErrorNum = rc
   Me.ErrorMsg = WnetError(rc)

End Sub

Public Sub DisConnect(sDrive As String)
   
   On Error GoTo Err_DisConnect
   Me.ErrorNum = 0
   Me.ErrorMsg = ""
   rc = WNetCancelConnection(sDrive + Chr(0), 0)
   If rc <> 0 Then GoTo Err_DisConnect
   
   Exit Sub
Err_DisConnect:
   Me.ErrorNum = rc
   Me.ErrorMsg = WnetError(rc)

End Sub

Private Function WnetError(Errcode As Long) As String

   Select Case Errcode
      Case WN_Not_Supported:
         WnetError = "Function is not supported."
      Case WN_Out_Of_Memory:
         WnetError = "Out of Memory."
      Case WN_Net_Error:
         WnetError = "An error occurred on the network."
      Case WN_Bad_Pointer:
         WnetError = "The Pointer was Invalid."
      Case WN_Bad_NetName:
         WnetError = "Invalid Network Resource Name."
      Case WN_Bad_Password:
         WnetError = "The Password was Invalid."
      Case WN_Bad_Localname:
         WnetError = "The local device name was invalid."
      Case WN_Access_Denied:
         WnetError = "A security violation occurred."
      Case WN_Already_Connected:
         WnetError = "The local device was connected to a remote resource."
      Case Else:
         WnetError = "Unrecognized Error " + str(Errcode) + "."
   End Select

End Function


0
 

Author Comment

by:darink
ID: 1468002
thanks, ill let you know as soon as i install nt

0
 

Author Comment

by:darink
ID: 1468003
also, wouldnt read/write access to the drive be desired?  i dont want to be running my lan in that fassion, jsut so we can chat.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question