Made this game in order to learn internet programming, it's a simple twoplayer game where the goal is to place 5 marks in a straight line and prevent your opponent from doing so. The game works fine when I run two copies of it on my own machine and use the local ip for both of them (127.0.0.1). But when playing over the internet, the host can't send his first data package, however the host will recieve the ready message from the client, so some of it works. I'm using "port" 8765 and 8766, whatever that might be, and if that is wrong, then how can the first message go troug? Can anybody help me?
If you want to exec it pleace load the game from my storeroom (would like to call it a homepage)
If you want to exec it pleace load the game from my storeroom (would like to call it a homepage)
Global plno=1 Global x Global y Global turn Const boardsize=16 ip$=Input("Enter opponents IP: ") strmGame=OpenTCPStream(ip,8765) If strmgame=0 Then svrGame=CreateTCPServer(8765) Print "Reciever didn't answer, wait for call" Else WriteString strmGame,"Ready" CloseTCPStream strmgame Print "Reciever answered, establishing contact" plno=2 End If If plno=1 Then Repeat strtream=AcceptTCPStream(svrGame) If strtream<>0 Then alpha$=ReadString$(strtream) If alpha="Ready" Then Exit End If Delay 10 Forever Else svrGame=CreateTCPServer(8766) End If Graphics boardsize*16,boardsize*16,32,2 ClsColor 255,255,0 Cls Color 0,0,0 For a=0 To boardsize Rect a*16-1,0,2,boardsize*16 Rect 0,a*16-1,boardsize*16,2 Next Dim board(boardsize+1,boardsize+1) Dim mark(1) mark(0)=LoadImage("1.bmp") mark(1)=LoadImage("2.bmp") turn=1 Repeat If turn=plno Then Delay 200 .nogood While Not MouseDown(1) Delay 5 Wend x=MouseX()/16 y=MouseY()/16 If board(x+1,y+1)<>0 Then Goto nogood DrawImage mark(plno-1),x*16,y*16 board(x+1,y+1)=plno .nogood2 strmGame=OpenTCPStream(ip,8767-plno) If strmgame=0 Then Goto nogood2 WriteByte strmGame,x WriteByte strmgame,y CloseTCPStream strmgame Else strtream=0 While strtream=0 strtream=AcceptTCPStream(svrGame) Delay 5 Wend x=ReadByte(strtream) y=ReadByte(strtream) board(x+1,y+1)=turn DrawImage mark(2-plno),x*16,y*16 End If Dim l(3) Dim active(7) For nostep=1 To 4 check(0,1,0,nostep) check(1,1,1,nostep) check(1,0,2,nostep) check(1,-1,3,nostep) Next turn=3-turn Forever Function check(x1,y1,lineno,factor) If active(lineno)=0 Then If board(x+1+x1*factor,y+1+y1*factor)=turn Then l(lineno)=l(lineno)+1 If board(x+1+x1*factor,y+1+y1*factor)<>turn Then active(lineno)=1 End If If active(lineno+4)=0 Then If board(x+1-x1*factor,y+1-y1*factor)=turn Then l(lineno)=l(lineno)+1 If board(x+1-x1*factor,y+1-y1*factor)<>turn Then active(lineno+4)=1 End If If l(lineno)=>4 Then Rect 0,0,boardsize*16,16 Color 0,255,255 If turn=plno Then Print "You are victorious!" If turn<>plno Then Print "You have lost!" WaitKey() End End If End Function