Código [Seleccionar]
#include <iostream>
int main()
{
std::cout << "Buenas foro!";
}
en mi tiempo libre , a modo de hobby programo juegos 2d en VBS+HTA y hace poco quise volver a hacer uno con sockets y me encontre con que desde windows 7 en adelante la cosa de los sockets se complica. Y pense hago un "socket server" y para que sea online y gratuito hice una simple base de datos en un server gratuito y un script php que se encarga de leer y actualizar en la base de datos las posiciones y estados de todos los elementos del juego.en fin. nada del otro mundo pero una solucion rapida para los que quieren un atajo bastante ineficiente pero mucho mucho mas corto

index.php
Código [Seleccionar]
<HTML>
<HEAD>
<TITLE>Servidor - Pseudo Socket by JohnConnor</TITLE>
</HEAD>
<BODY>
<?
$con = mysqli_connect("mysql.h********.com.ar","usuario_data","*******");
mysqli_select_db($con,"basededatos_sisdb");
$conexión = $_GET['tc'];
If ($conexión == "crear") {
$ns = $_GET['ns'];
$ds = $_GET['ds'];
mysqli_query($con,"insert into servidores (servername,dataserver,dataclient) values ('$ns','$ds','vacio')");
}
If ($conexión == "jugador1") {
$idserver = $_GET['sid'];
$ds = $_GET['ds'];
$result = mysqli_query($con,"Update servidores Set dataserver='$ds' Where id='$idserver'");
mysqli_query($con,$result);
$result2 = mysqli_query($con,"SELECT *
FROM `servidores`
WHERE `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($result2)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}
If ($conexión == "jugador2") {
$idserver = $_GET['sid'];
$dc = $_GET['dc'];
$resultdc = mysqli_query($con,"Update servidores Set dataclient='$dc' Where id='$idserver'");
mysqli_query($con,$resultdc);
$result2dc = mysqli_query($con,"SELECT *
FROM `servidores`
WHERE `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($result2dc)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}
If ($conexión == "spectator") {
$idserver = $_GET['sid'];
$resultsp = mysqli_query($con,"SELECT *
FROM `servidores`
WHERE `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($resultsp)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}
mysqli_close($con);
?>
</BODY>
</HTML>
Server VBS (a modo de demostración)
Código (vb) [Seleccionar]
<HTML>
<HEAD>
<TITLE>JugadorUno Socket_Server by JohnConnor</TITLE>
<HTA:APPLICATION
ID = "JCApp"
APPLICATIONNAME = "JugadorUno Socket_Server by JohnConnor"
BORDER = "thick"
CAPTION = "yes"
ICON = "app.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "no"
MAXIMIZEBUTTON = "yes"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
>
</HEAD>
<BODY>
<DIV id="pos">0</div>
<img src="ju.png" id="jugadoruno">
<img src="jd.png" id="jugadordos">
</BODY>
</HTML>
<SCRIPT LANGUAGE="VBScript">
Dim Socket
Set Socket = CreateObject("MSXML2.XMLHTTP")
Dim TeclaW
Dim TeclaS
Dim TeclaA
Dim TeclaD
Dim JUposX
Dim JUposY
Dim JDposX
Dim JDposY
jugadoruno.Style.Position = "Absolute"
jugadordos.Style.Position = "Absolute"
Public Sub Window_OnLoad()
Self.ResizeTo 800,600
Call SocketServer()
Call Main()
End Sub
Public Sub Main()
On Error Resume Next
jugadoruno.style.top = cint(JUposY)
jugadoruno.style.left = cint(JUposX)
jugadordos.style.top = cint(JDposY)
jugadordos.style.left = cint(JDposX)
If TeclaW = 1 Then : Call juMovY(-5) : ENd If
If TeclaS = 1 Then : Call juMovY(5) : End If
If TeclaA = 1 Then : Call juMovX(-5) : End If
If TeclaD = 1 Then : Call juMovX(5) : End If
Tiempo = Window.SetTimeOut("Main()",27)
End Sub
Public Sub juMovX(mov)
JUposX = JuposX + cInt(mov)
End Sub
Public Sub juMovY(mov)
JUposY = JuposY + cInt(mov)
End Sub
Public Sub Document_OnKeyPress
If Window.Event.KeyCode = "119" Or Window.Event.KeyCode = "87" Then : TeclaW = 1 : End If
If Window.Event.KeyCode = "115" Or Window.Event.KeyCode = "83" Then : TeclaS = 1 : End If
If Window.Event.KeyCode = "97" Or Window.Event.KeyCode = "65" Then : TeclaA = 1 : End If
If Window.Event.KeyCode = "100" Or Window.Event.KeyCode = "68" Then : TeclaD = 1 : End If
End Sub
Public Sub Document_OnKeyUp
If Window.Event.KeyCode = "87" Then : TeclaW = 0 : End If
If Window.Event.KeyCode = "83" Then : TeclaS = 0 : End If
If Window.Event.KeyCode = "65" Then : TeclaA = 0 : End If
If Window.Event.KeyCode = "68" Then : TeclaD = 0 : End If
End Sub
Public Sub SocketServer()
Socket.Open "GET", "http://spaceinvaders2.hol.es/?sid=2&tc=jugador1&ds=" & JuposX & ":" & JUposY , False
Socket.Send
A_JUPOS = Split(Socket.ResponseText,"@")
B_JUPOS = Split(A_JUPOS(3),":")
JDposX = B_JUPOS(0)
JDposYa = Split(B_JUPOS(1),"<")
JDposY = JDposYa(0)
pos.innerhtml = JDposX & " - " & JDposY
TiempoS = Window.SetTimeOut("SocketServer()",500)
End Sub
</SCRIPT>
y por utlimo el cliente:
Código (vb) [Seleccionar]
<HTML>
<HEAD>
<TITLE>JugadorDos Socket_Client by JohnConnor</TITLE>
<HTA:APPLICATION
ID = "JCApp"
APPLICATIONNAME = "JugadorDos Socket_Client by JohnConnor"
BORDER = "thick"
CAPTION = "yes"
ICON = "app.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "no"
MAXIMIZEBUTTON = "yes"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
>
</HEAD>
<BODY>
<img src="ju.png" id="jugadoruno">
<img src="jd.png" id="jugadordos">
</BODY>
</HTML>
<SCRIPT LANGUAGE="VBScript">
Dim Socket
Set Socket = CreateObject("MSXML2.XMLHTTP")
Dim TeclaW
Dim TeclaS
Dim TeclaA
Dim TeclaD
Dim JUposX
Dim JUposY
Dim JDposX
Dim JDposY
jugadoruno.Style.Position = "Absolute"
jugadordos.Style.Position = "Absolute"
Public Sub Window_OnLoad()
Self.ResizeTo 800,600
Call SocketServer()
Call Main()
End Sub
Public Sub Main()
On Error Resume Next
jugadordos.style.top = cint(JUposY)
jugadordos.style.left = cint(JUposX)
If TeclaW = 1 Then : Call juMovY(-5) : ENd If
If TeclaS = 1 Then : Call juMovY(5) : End If
If TeclaA = 1 Then : Call juMovX(-5) : End If
If TeclaD = 1 Then : Call juMovX(5) : End If
Tiempo = Window.SetTimeOut("Main()",27)
End Sub
Public Sub juMovX(mov)
JUposX = JuposX + cInt(mov)
End Sub
Public Sub juMovY(mov)
JUposY = JuposY + cInt(mov)
End Sub
Public Sub Document_OnKeyPress
If Window.Event.KeyCode = "119" Or Window.Event.KeyCode = "87" Then : TeclaW = 1 : End If
If Window.Event.KeyCode = "115" Or Window.Event.KeyCode = "83" Then : TeclaS = 1 : End If
If Window.Event.KeyCode = "97" Or Window.Event.KeyCode = "65" Then : TeclaA = 1 : End If
If Window.Event.KeyCode = "100" Or Window.Event.KeyCode = "68" Then : TeclaD = 1 : End If
End Sub
Public Sub Document_OnKeyUp
If Window.Event.KeyCode = "87" Then : TeclaW = 0 : End If
If Window.Event.KeyCode = "83" Then : TeclaS = 0 : End If
If Window.Event.KeyCode = "65" Then : TeclaA = 0 : End If
If Window.Event.KeyCode = "68" Then : TeclaD = 0 : End If
End Sub
Public Sub SocketServer()
Socket.Open "GET", "http://spaceinvaders2.hol.es/?sid=2&tc=jugador2&dc=" & JuposX & ":" & JUposY , False
Socket.Send
A_JUPOS = Split(Socket.ResponseText,"@")
B_JUPOS = Split(A_JUPOS(2),":")
JDposX = B_JUPOS(0)
JDposY = B_JUPOS(1)
On Error Resume Next
jugadoruno.style.top = cint(JDposY)
jugadoruno.style.left = cint(JDposX)
TiempoS = Window.SetTimeOut("SocketServer()",500)
End Sub
</SCRIPT>
Aclaro que es una demostracion simplemente porque solo se mueven dos jugadores por una ventana, y solo se actualiza al pular una tecla.
Bueno, como ven no soy bueno explicando pero cualquier duda concreta que tengan o ayuda que necesiten comenten. Saludos