Bueno, como dice el t?tulo, cuando trato de ejecutar el servidor y me conecto como cliente, sale un error:
(http://img19.imageshack.us/img19/9705/error1rq.png)
Y en step tengo esto:
//Message handling - See Message IDs.txt for more info.
/* ==================== */
/* -START- */
/* ==================== */
/* New Connection Stuff */
/* ==================== */
//Create the variables to be used
var clientsocket, player;
//First, accept any new connections
clientsocket = tcpaccept(servertcp,true);
//If no one is there, exit
if (clientsocket <=0) exit;
//Blocking mode
setsync(clientsocket,0);
//Receive the client's username
receivemessage(clientsocket);
name = readstring();
//Check for a free space
if (instance_number(obj_client) = 20)
{
//If there isn't a free space, we tell the client
clearbuffer();
writebyte(2);
sendmessage(clientsocket);
exit;
}
//Now we search through the player list to get the player's id. If a place in the list is -1 then that means that it's a free space
for(i=0; i < 20; i+=1)
{
//So when we find a -1 we break from the loop
if (global.players[i]==-1) break;
}
//Now, we send the player id to the client using message ID 1...
clearbuffer();
writebyte(1);
writebyte(i);
sendmessage(clientsocket);
//We create the player
player = instance_create(0,0,obj_client);
//Store their player id in the object
player.pid = i;
//Store the socket that they used to connect to the server with. NOTE: This will not be the same as the port specified in the tcpconnect() in the client.
player.tcp = clientsocket;
//Store their username
player.username = name;
//Then we store the player id in the player id list.
global.players[i] = player;
//...and then we send the player id and username to everyone else...
clearbuffer();
writebyte(3);
writebyte(i);
writestring(name,true);
with(obj_client)
{
if (id!=player)
{
sendmessage(tcp);
}
}
//...and then make all the clientz who are already on the server tell the new player that they're here.
with(obj_client)
{
if (id!=player)
{
clearbuffer();
writebyte(3);
writebyte(pid);
writestring(username,true);
sendmessage(clientsocket);
}
}
//None
setsync(clientsocket,1);
//Add "this player has joined" message
script_addline(name + " has joined.",c_black);
/* ==================== */
/* -END- */
/* ==================== */
/* New Connection Stuff */
/* ==================== */
Aclaro que no lo hice yo, es un ejemplo que solo lo estoy adaptando.
Desde ya, muchas gracias ^^
Tenes un error en la concatenacion.
*string(str)=convierte a cadena una variable.
script_addline(string(name)+" has joined.",c_black);
Eso ya lo intent?, ahora sale "0 as joined" y desde el cliente sale un cartel diciendo que no se pudo conectar :S
vaya es muy raro porque al parecer name es una string ya que tuvo una asignacion a readstring()...el error parece provenir del cliente que no envia esa string, entonces el servidor no tiene nada que leer...fijate bien el orden de acciones y comunicaciones entre clientes y servidor
Saludos 8)
PD: Yo tambien use ese ejemplo pero lo super mega adapte (casi ni se parece al ejemplo xD)
Lo mas extra?o es que el cliente que estoy haciendo tiene exactamente lo mismo que el del ejemplo, tiene los mismos script y todo :S. Este es el c?digo del step del cliente por si puede ser de hay el error:
/* ==================== */
/* -START- */
/* ==================== */
/* Receiving Messages */
/* ==================== */
//Create the variables to be used
var messagesize, messageid;
//Check for messages
while(1)
{
//Receive the message using TCP
messagesize = receivemessage(global.clienttcp);
//If no message was received, break
if (messagesize <= 0) break;
//If a message was received, get the message ID...
messageid = readbyte();
//Set the ping to 0 because we got a message
ping = 0;
//...and then use it to check what message it was
switch(messageid)
{
//If the message ID is 1
case 1:
//Store the message as our player ID
global.myid = readbyte();
obj_player_self.alarm[0] = 1;
//And then break from the loop. If you forget this part then you might get errors.
break;
case 2:
//Server is full message
closesocket(global.clienttcp);
closesocket(global.clientudp);
dllfree();
show_message("Sorry! The server is full.");
game_end();
break;
case 3:
//New Player (create)
var userid, name, user;
userid = readbyte();
user = instance_create(obj_personaje.xstart,obj_personaje.ystart,obj_personaje_other);
user.pid = userid;
name = readstring();
user.username = name;
players[userid] = user;
script_addline(name + " has joined.",c_black);
break;
case 4:
//New Player (chat message)
var name, userid;
userid = readbyte();
name = readstring();
user = players[userid];
user.username = name;
script_addline(name + " has joined.",c_black);
break;
case 5:
//Update other players' positions
value = readbyte();
player = players[value];
player.x = readshort();
player.y = readshort();
player.sprite_index = readshort();
player.image_speed = readshort();
player.image_index = readshort();
break;
case 6:
//Player left
var playerid, username;
playerid = readbyte();
username = readstring();
script_addline(username + " has left.",c_black);
with(players[playerid])
{
instance_destroy();
}
players[playerid] = -1;
break;
case 7:
//The server has shut down
show_message("The server has shut down.");
game_end();
break;
case 8:
//Chat message
script_addline(readstring(),c_black);
break;
case 9:
//Server message
script_addline("Server: " + readstring(),c_red);
break;
}
}
//If we didn't get anything, we add the time to our ping
ping += current_time - deltatime;
deltatime = current_time;
//Check to see if we timed out
if(ping > timeout)
{
show_message("You have timed out.");
game_end();
}