Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UDP stupid question

Status
Not open for further replies.

foxprogram

Programmer
Aug 31, 2004
28
0
0
HU
Hello!

I would like to use my PONG :) game by network with 2 machines. I would like to send positions of the player's figure to each other.

I use winsock object, and I have a problem:

THISFORM.olecontrol1.Object.Protocol=1
THISFORM.olecontrol1.Object.RemoteHost="user1"
THISFORM.olecontrol1.Object.RemotePort=9022

THISFORM.olecontrol1.Object.localPort=9022
THISFORM.olecontrol1.Object.Bind(9022)

karakterek=alltrim(str(120)) && .top coordinate of the player one's figure
THISFORM.olecontrol1.Object.SendData(karakterek)

If I try to use sendData method, I always get this error message:

"OLE IDispatch exception code 0 from winsock:Invalid argument..."

And the same situation, if I try to use the getData method.
What whould be the problem ?
 
Foxprogram,

You might get that error if you are not truly bound to the remote host. I duplicated your error with just setting up the local side. When I added the remote side everything worked as advertised. Create a test form with two winsock controls and put this code in the click of a button:

Code:
THISFORM.olecontrol1.Protocol=1
THISFORM.olecontrol1.RemoteHost="localhost"
THISFORM.olecontrol1.RemotePort="9023"

THISFORM.olecontrol2.Protocol=1
THISFORM.olecontrol2.RemoteHost="localhost"
THISFORM.olecontrol2.RemotePort="9022"

THISFORM.olecontrol1.Bind("9022")
THISFORM.olecontrol2.Bind("9023")

IF THISFORM.olecontrol1.state = 1
	karakterek=ALLTRIM(STR(120))
	THISFORM.olecontrol1.SendData(karakterek)
ENDIF

In the DataArrival event of the 2nd control put this code:

Code:
*** ActiveX Control Event ***
LPARAMETERS bytestotal
lcString = ""
THISFORM.oleControl2.GetData(@lcString, 8, bytestotal)
? lcString

When you click the button you should see the result that was passed from the 1st control to the 2nd control. This should get you communicating and you should be able to expand from there.

Andy

 
Thx!

I put these lines into my form, and now I have the follownig message:

"...Invalid operation at current state"

After I press Ignore, your example works fine, but this error message is shown every time when I press the button.
???

 
Foxprogram,

The code above is the only code that I have in my entire form. Do you have any other code that is configuring the socket(s) before you press the button?

Andy
 
Andy's program only runs right once. I modified it a bit so it will continue to work with each press.
Code:
IF VARTYPE(Thisform.firsttime) <> "L"
	Thisform.AddProperty("firsttime", .T.)


	THISFORM.olecontrol1.Protocol=1
	THISFORM.olecontrol1.RemoteHost="localhost"
	THISFORM.olecontrol1.RemotePort="9023"

	THISFORM.olecontrol2.Protocol=1
	THISFORM.olecontrol2.RemoteHost="localhost"
	THISFORM.olecontrol2.RemotePort="9022"

	THISFORM.olecontrol1.Bind("9022")
	THISFORM.olecontrol2.Bind("9023")

ENDIF
IF THISFORM.olecontrol1.state = 1
    karakterek = ttoc(DATETIME(), 3)
    THISFORM.olecontrol1.SendData(karakterek)
ENDIF
Note: I only modified the button's click code.

Rick
 
Thank you!

I replaced the 2 Winsock on my form to another two winsock, and now everything is fine.
But I cannot see yet, how could I use a form with 2 winsock to send machines to each other coordinates during the gameplay ...

Any idea for my Pong style game ? :)
 
OK. I did it !!!

Now user should type the name of the machine in the local network, and what the user type into a text, the other side would display it. Just like a chat ! :)

Thank you guys!
foxprogram
 
Another question.

How can I recognize that who connected / requested / send me anything ?

Should I know the IP address of that machine ???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top