I 'm trying to make a server, but I have a problem, in fact my server works if the client come from the same network that the server, for instance I have 2 psp at home, one is the server and the other is the client , the client connect perfectly to the server , but if I want one of my friend connect to my PSP server it doesn't work although I've modified client source code, modifying this line :
server.sin_addr.s_addr = inet_addr("192.168.1.13 ");
by this one :
server.sin_addr.s_addr = inet_addr("90.21.51.33");
But it still doesn't work (the client returns it cannot connect the server). And I really don't know how to solve the probleme so if you can help me :)
Here is psp server code :
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <string.h>
#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <psputility.h>
#include <sys/select.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
#define MODULE_NAME "Test"
#define printf pspDebugScreenPrintf
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef struct in_addr IN_ADDR;
PSP_MODULE_INFO("Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int exit_callback(int arg1, int arg2, void *common);
int CallbackThread(SceSize args, void *argp);
int SetupCallbacks(void);
/* Connection a un point d'acces */
int connect_to_apctl(int config)
{
int err;
int stateLast = -1;
/* Connection utilisant un profile */
err = sceNetApctlConnect(config);
if (err != 0)
{
printf(MODULE_NAME ": sceNetApctlConnect returns %08X\n", err);
return 0;
}
printf(MODULE_NAME ": Connecting to internet...\n\n");
while (1)
{
int state;
err = sceNetApctlGetState(&state);
if (err != 0)
{
printf(MODULE_NAME ": sceNetApctlGetState returns $%x\n", err);
break;
}
if (state > stateLast)
{
printf(" connection state %d of 4.\n", state);
stateLast = state;
}
if (state == 4)
break; // connection avec Ip static
// Attente
sceKernelDelayThread(50*1000); // 50ms
}
printf(MODULE_NAME ": Connected to internet.\n\n");
if(err != 0)
{
return 0;
}
return 1;
}
int main(int argc, char **argv)
{
SetupCallbacks();
pspDebugScreenInit();
//Chargement du Modules inet
sceUtilityLoadNetModule(1);
sceUtilityLoadNetModule(3);
int err;
do
{
if((err = pspSdkInetInit()))
{
printf(MODULE_NAME ": Error, could not initialise the network %08X\n", err);
break;
}
if(connect_to_apctl(1))
{
// Connecté et lance un test d'IP
char szMyIPAddr[32];
if (sceNetApctlGetInfo(8, szMyIPAddr) != 0) strcpy(szMyIPAddr, "unknown IP address");
SOCKET s_server;
s_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s_server == INVALID_SOCKET) printf("La fonction socket a echoue.\n");
else
{
SOCKADDR_IN server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(3500);
if (bind(s_server, (SOCKADDR *)&server, sizeof(server)) == SOCKET_ERROR) printf("La fonction bind a echoue.\n");
else
{
if (listen(s_server, 0) == SOCKET_ERROR) printf("La fonction listen a echoue.\n");
else
{
SOCKET s_client;
SOCKADDR_IN client;
size_t csize = sizeof(client);
s_client = accept(s_server, (SOCKADDR *)&client, &csize);
if (s_client == INVALID_SOCKET) printf("La fonction accept a echoue.\n");
else
{
char buffer[100];
printf("Le client %s s'est connecte !\n", inet_ntoa(client.sin_addr));
sceNetInetSend(s_client, "Bonjour", (int)strlen("Bonjour") + 1, 0);
sceNetInetRecv(s_client, buffer, sizeof(buffer), 0);
printf("%s\n", buffer);
closesocket(s_client);
}
}
}
closesocket(s_server);
}
}
} while(0);
return 0;
}
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <string.h>
#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <psputility.h>
#include <sys/select.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
#define MODULE_NAME "Test"
#define printf pspDebugScreenPrintf
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef struct in_addr IN_ADDR;
PSP_MODULE_INFO("Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int exit_callback(int arg1, int arg2, void *common);
int CallbackThread(SceSize args, void *argp);
int SetupCallbacks(void);
/* Connection a un point d'acces */
int connect_to_apctl(int config)
{
int err;
int stateLast = -1;
/* Connection utilisant un profile */
err = sceNetApctlConnect(config);
if (err != 0)
{
printf(MODULE_NAME ": sceNetApctlConnect returns %08X\n", err);
return 0;
}
printf(MODULE_NAME ": Connecting to internet...\n\n");
while (1)
{
int state;
err = sceNetApctlGetState(&state);
if (err != 0)
{
printf(MODULE_NAME ": sceNetApctlGetState returns $%x\n", err);
break;
}
if (state > stateLast)
{
printf(" connection state %d of 4.\n", state);
stateLast = state;
}
if (state == 4)
break; // connection avec Ip static
// Attente
sceKernelDelayThread(50*1000); // 50ms
}
printf(MODULE_NAME ": Connected to internet.\n\n");
if(err != 0)
{
return 0;
}
return 1;
}
int main(int argc, char **argv)
{
SetupCallbacks();
pspDebugScreenInit();
//Chargement du Modules inet
sceUtilityLoadNetModule(1);
sceUtilityLoadNetModule(3);
int err;
do
{
if((err = pspSdkInetInit()))
{
printf(MODULE_NAME ": Error, could not initialise the network %08X\n", err);
break;
}
if(connect_to_apctl(1))
{
// Connecté et lance un test d'IP
char szMyIPAddr[32];
if (sceNetApctlGetInfo(8, szMyIPAddr) != 0) strcpy(szMyIPAddr, "unknown IP address");
SOCKET sockListen;
sockaddr_in addrListen;
int error;
sockListen = sceNetInetSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockListen <= 0)
{
printf("socket returned $%x\n", sockListen);
sceKernelDelayThread(500*1000);
break;
}
addrListen.sin_family = AF_INET;
addrListen.sin_addr.s_addr = inet_addr("90.21.51.33");
addrListen.sin_port = htons(3500);
err = sceNetInetConnect(sockListen, (sockaddr *)&addrListen, sizeof(addrListen));
if (err != 0)
{
printf("Unable to connect!\n");
printf("connect returned $%x\n", err);
printf(" errno=$%x\n", sceNetInetGetErrno());
sceKernelDelayThread(500*1000);
break;
}
else
{
printf("A reussi a ce connecter");
char buffer[] = "Humand";
char buffer2[1000];
sceNetInetSend(sockListen, buffer, strlen(buffer), 0);
sceNetInetRecv(sockListen, (u8*)buffer2, sizeof(buffer2)-1, 0);
printf("%s",buffer2);
}
}
}
while(0);
return 0;
}
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread,
0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
See you .