Solved

how to pass variables over a lan

Posted on 1998-08-05
12
212 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
Comment Utility
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
Comment Utility
can you say any more?
0
 

Author Comment

by:darink
Comment Utility
can you say any more?
0
 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

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

Expert Comment

by:waty
Comment Utility
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
Comment Utility
would maping network drives be easiest for that?

0
 
LVL 14

Expert Comment

by:waty
Comment Utility
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
Comment Utility
thanks, ill let you know as soon as i install nt

0
 

Author Comment

by:darink
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now