Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 08, 2012, 06:51:52 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Check out the Code Section!
Home Help Search Shop Login Register
Digg This!
Pages: [1] 2
Print
Author Topic: UDP or TCP/IP?  (Read 4900 times)
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« on: September 10, 2009, 08:19:09 PM »

hi people, i would like to know if the default socket for PSP wireless in the wificontroller programme is it UDP or TCP/IP?
Logged


AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #1 on: September 11, 2009, 08:03:22 AM »

TCP

...

Well...

If you follow the guides and such that are provided it'll be TCP.  I haven't tried it but it's possible that all the connection types are available.  It depends on how you created the connection.
« Last Edit: September 11, 2009, 03:29:20 PM by AlphaDingDong » Logged
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #2 on: September 13, 2009, 10:37:54 PM »

there are guides? whoa. i'm really lost at programming the PSP to control  a device such as a robot wirelessly. does this website has guides?

is it possible to directly connect the psp to the device instead of connecting to a computer then to a device?

thanks! Smile
Logged
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #3 on: September 13, 2009, 11:30:03 PM »

Code:
/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Simple elf based network example.
 *
 * Copyright (c) 2005 James F <tyranid@gmail.com>
 * Some small parts (c) 2005 PSPPet
 *
 * $Id: main.c 1887 2006-05-01 03:54:06Z jim $
 * $HeadURL: svn://svn.pspdev.org/psp/trunk/pspsdk/src/samples/net/simple/main.c $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <errno.h>

#define printf pspDebugScreenPrintf

#define MODULE_NAME "NetSample"
#define HELLO_MSG   "Hello there. Type away.\r\n"

#define PORT 1234
#define RCVBUFSIZE 8192
#define INADDR_NONE ((unsigned long) -1)

PSP_MODULE_INFO(MODULE_NAME, 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
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;
}

#define SERVER_PORT 1234

int make_socket(uint16_t port)
{
int sock;
int ret;
struct sockaddr_in name;

sock = socket(PF_INET, SOCK_STREAM, 0);
if(sock < 0)
{
return -1;
}

name.sin_family = AF_INET;
name.sin_port = htons(port);
name.sin_addr.s_addr = htonl(INADDR_ANY);
ret = bind(sock, (struct sockaddr *) &name, sizeof(name));
if(ret < 0)
{
return -1;
}

return sock;
}

/* Start a simple tcp echo server */
void connect_and_send(const char *szIpAddr)
{
    struct sockaddr_in server;
    //struct hostent *host_info;
    unsigned long addr;

    int sock;

    char *echo_string;
    int echo_len;


    /* Creating Socket */
    sock = socket( AF_INET, SOCK_STREAM, 0 );
    if (sock < 0)
        printf("Error creating socket\n");

    /* Creating socketadress of the Server
     * Consists of type, IP-adress and portnumber */
    memset( &server, 0, sizeof (server));
    if ((addr = inet_addr("192.168.178.33")) != INADDR_NONE) {
        memcpy( (char *)&server.sin_addr, &addr, sizeof(addr));
    } else {
        printf("Error creating the server's socketadress\n");
    }
    /* IPv4-connection */
    server.sin_family = AF_INET;
    /* Portnumber */
    server.sin_port = htons( PORT );

    /* Connecting to server */
    if(connect(sock,(struct sockaddr*)&server,sizeof(server)) <0)
        printf("Cannot connect to server\n");

    /* echostring */
    echo_string = "hello";
    /* echostring's length */
    echo_len = strlen(echo_string);

    /* Sending the string to the server */
    if (send(sock, echo_string, echo_len, 0) != echo_len)
        printf("send() hat eine unterschiedliche Anzahl"
                   " von Bytes versendet, als erwartet !!!!");

    /* Close connetion and socket */
   close(sock);
}

/* Connect to an access point */
int connect_to_apctl(int config)
{
int err;
int stateLast = -1;

/* Connect using the first profile */
err = sceNetApctlConnect(config);
if (err != 0)
{
printf(MODULE_NAME ": sceNetApctlConnect returns %08X\n", err);
return 0;
}

printf(MODULE_NAME ": Connecting...\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;  // connected with static IP

// wait a little before polling again
sceKernelDelayThread(50*1000); // 50ms
}
printf(MODULE_NAME ": Connected!\n");

if(err != 0)
{
return 0;
}

return 1;
}

int net_thread(SceSize args, void *argp)
{
int err;

do
{
if((err = pspSdkInetInit()))
{
printf(MODULE_NAME ": Error, could not initialise the network %08X\n", err);
break;
}

if(connect_to_apctl(1))
{
// connected, get my IPADDR and run test
char szMyIPAddr[32];
if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
strcpy(szMyIPAddr, "unknown IP address");

connect_and_send(szMyIPAddr);
}
}
while(0);

return 0;
}

/* Simple thread */
int main(int argc, char **argv)
{
SceUID thid;

SetupCallbacks();

pspDebugScreenInit();

if(pspSdkLoadInetModules() < 0)
{
printf("Error, could not load inet modules\n");
sceKernelSleepThread();
}

/* Create a user thread to do the real work */
thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if(thid < 0)
{
printf("Error, could not create thread\n");
sceKernelSleepThread();
}

sceKernelStartThread(thid, 0, NULL);

sceKernelExitDeleteThread(0);

return 0;
}


Hi how does this work? i used cygwin to make file, however when i try to run it on the PSP, it gives the error, (80020148) , the game cannot be started. why? Is it not meant for running as a normal program in the PSP?
Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #4 on: September 14, 2009, 08:52:43 AM »

That example is meant to run in Kernel mode, which requires 1.50 firmware (available on Phat only).

As for connecting directly to a device, it is possible in terms of hardware by using ad-hoc, but I've looked a long time and haven't been able to find any information about how to use ad-hoc for non-psp connections.  Sad

If you find out then please let me know.  Until then we'll have to continue to bounce through a wireless router.

I can show you some working code for user mode, but first I have to ask whether or not you know C++ or just C.

Alternatively I can show you an adaptation of the code you posted there that gets it to run in user mode, but that code uses the crappy AP connection method instead of the sexy dialog based one.

Your call.  I have it all in my archives.
Logged
TrigZu
Newbie
*

Karma: +0/-1
Offline Offline

Posts: 16
432.41 points

View Inventory
Send Money to TrigZu


View Profile
« Reply #5 on: September 16, 2009, 03:29:33 PM »

I would like to learn how to make a UDP connection.

I'll post back in a few days if I can't find it out myself.
Logged
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #6 on: September 17, 2009, 05:10:15 AM »

dear AlphaDingDong

yes i know C++. Thanks Smile i would like to see the code in user mode. that would really help a lot. thanks. :)I really appreciate your help.

sels
Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #7 on: September 17, 2009, 10:55:54 AM »

My code:

You can look through this and get an example of creating a TCP socket connection.  Note that the AP connect dialog requires that the GU be prepared before use.  Also the code here makes calls to functions from other namespaces that are not present here such as Debug:: and Graphics::.  It should be fairly clear what needs to be done though.

As far as adding libs to the makefile, it turns out that the SDK already links them by default.  Smile

net.h
Code:
#ifndef NET_MODULE
#define NET_MODULE
#include <netinet/in.h>

namespace Net {
  void initialize(); //prepare for use
  int connectAP(bool overdraw = false);
  uint32_t nslookup(const char* hostname); //return uint32_t IP address for 'hostname'
  bool isInit(); //returns whether or not init has run
};

class TCPSocket {
  public:
    TCPSocket(const char* host, unsigned short port);
    ~TCPSocket();
    void close();
    const char* host();
    unsigned short port();
    void send(void* data, int length);
    int recv(void* buffer, int length);
    int peek(void* buffer, int length);
  private:
    int sock;
    struct sockaddr_in name;
    char* hostname;
    unsigned short portnum;
    uint32_t get_ip_from_str(const char* host);
};

#endif

net.cpp
Code:
//{SciTE folding - PSP Net/NetPlay inclusions
#include <pspsdk.h>
#include <unistd.h>
#include <pspnet.h>
#include <psputility.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <pspwlan.h>
#include <errno.h>
#include <cstring>
#include "debug.h" //This is my own debug mod.  You'll need to write one or replace calls below.
#include "graphics.h" //The GU needs to be prepared for use before connecting to an AP.
#include "net.h"
//}

char local_address[32];
bool net_initialized = false;

void Net::initialize() { //prepare for use
  if(net_initialized) {return;}
  memset(local_address, 0, 32);
  sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON); //Load the net module
  sceUtilityLoadNetModule(PSP_NET_MODULE_INET); //Load the internet module
  sceNetInit(128*1024, 42, 4*1024, 42, 4*1024); //No documentation.  Dunno what these values are.
  sceNetInetInit(); //Start up the inet engine
  sceNetApctlInit(0x8000, 48); //Start up the AP control system
  sceNetResolverInit(); //start the resolver lib (does this need to come after ap conn?)
  net_initialized = true;
}

int Net::connectAP(bool overdraw) { //run APCTL utility dialog (return 0 on success)
  if(Graphics::isInitialized() == false) {return -1;}
  pspUtilityNetconfData data; //Struct for dialog settings
  memset(&data, 0, sizeof(data)); //Clear it
  data.base.size = sizeof(data);
  data.base.language = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
  data.base.buttonSwap = PSP_UTILITY_ACCEPT_CROSS;
  data.base.graphicsThread = 18; //Set thread priority
  data.base.accessThread = 20; //Set thread priority
  data.base.fontThread = 19; //Set thread priority
  data.base.soundThread = 17; //Set thread priority
  data.action = PSP_NETCONF_ACTION_CONNECTAP;
  struct pspUtilityNetconfAdhoc adhocparam; //Struct to hold adhoc connection info (required)
  memset(&adhocparam, 0, sizeof(adhocparam)); //clear it
  data.adhocparam = &adhocparam; //Assign it
  sceUtilityNetconfInitStart(&data); //Start the dialog
  bool done = false;
  while(!done) { //Loop until trigger
    //{SciTE Folding - Clear screen
    if(overdraw) {
      Graphics::update();
    } else {
      Graphics::guStart();
      sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
      sceGuFinish();
      sceGuSync(0,0);
    }
    //}
    switch(sceUtilityNetconfGetStatus()) { //Operate according to reported dialog status
    case PSP_UTILITY_DIALOG_VISIBLE:
      sceUtilityNetconfUpdate(1); //Update the dialog
      break;
    case PSP_UTILITY_DIALOG_QUIT:
      sceUtilityNetconfShutdownStart(); //Tell the dialog to shut itself down
      break;
    case PSP_UTILITY_DIALOG_FINISHED:
    case PSP_UTILITY_DIALOG_NONE:
      done = true; //The dialog is done.  Break the loop
      break;
    }
    Graphics::flipScreen();
  }
  return sceNetApctlGetInfo(8, local_address);
}

uint32_t Net::nslookup(const char* hostname) { //return 'struct in_addr' for 'hostname'
  int rid = 0;
  void* buf = malloc(1024);
  if(sceNetResolverCreate(&rid, buf, 1024)) {
    Debug::msg("Failed to create resolver instance for '%s'.", hostname);
  }
  struct in_addr addrStruct;
  memset(&addrStruct, 0, sizeof(addrStruct));
  if(sceNetResolverStartNtoA(rid, hostname, &addrStruct, 3, 3)) {
    Debug::msg("Resolver could not find address for '%s'.", hostname);
  }
  sceNetResolverDelete(rid);
  free(buf);
  return addrStruct.s_addr;
}

bool Net::isInit() {
  return net_initialized;
}

TCPSocket::TCPSocket(const char* host, unsigned short port) {
  hostname = (char*)malloc(strlen(host));
  strcpy(hostname, host);
  portnum = port;
  sock = socket(PF_INET, SOCK_STREAM, 6);
  if(sock < 0) {
    Debug::msg("Unable to retrieve socket handle for '%s'.\nError code: %x", host, sock);
  }
  name.sin_family = AF_INET;
  name.sin_port = htons(port);
  name.sin_addr.s_addr = get_ip_from_str(host);
  int err = connect(sock, (struct sockaddr*)&name, sizeof(name));
  if(err) {
    Debug::msg("Could not establish socket connection to '%s'.\nError code %x", host, err);
  }
}

TCPSocket::~TCPSocket() {
  close();
}

void TCPSocket::close() {
  ::close(sock);
}

const char* TCPSocket::host() {
  return hostname;
}

unsigned short TCPSocket::port() {
  return portnum;
}

void TCPSocket::send(void* data, int length) {
  ::send(sock, data, length, 0);
}

int TCPSocket::recv(void* buffer, int length) {
  return ::recv(sock, buffer, length, 0);
}

int TCPSocket::peek(void* buffer, int length) {
  return ::recv(sock, buffer, length, MSG_PEEK);
}

uint32_t TCPSocket::get_ip_from_str(const char* host) {
  int oct[4] = {0,0,0,0};
  int result = sscanf(host, "%i.%i.%i.%i", &oct[0], &oct[1], &oct[2], &oct[3]);
  if(result == 4) {
    return __IPADDR((oct[0])|(oct[1]<<8)|(oct[2]<<16)|(oct[3]<<24));
  }
  return Net::nslookup(host);
}

--------------------------------------------------------------------------------
And this is the user-mode port of what you had there:

http://www.psp-programming.com/forums/index.php/topic,3186.msg26688.html#msg26688

--------------------------------------------------------------------------------
UDP is a little wierd.  It primarily uses datagrams instead of a socket connection and requires some form of synchronization for this reason.  I generally don't use UDP unless I have to and haven't tried it on the PSP, but Beej covers UDP transfer in his guide:

http://beej.us/guide/bgnet/

To be honest the only thing I've ever considered UDP for is nameserver communication, but the PSP has a builtin utility for that as can be seen in my code above.
« Last Edit: September 17, 2009, 11:01:18 AM by AlphaDingDong » Logged
gibbocool
Embellished by our ignorance
News Posters
Hero Member
*

Karma: +34/-11
Offline Offline

Posts: 822
2973.87 points

View Inventory
Send Money to gibbocool

Power Overwhelming


View Profile WWW
« Reply #8 on: September 18, 2009, 12:29:36 AM »

UDP is useful when TCP hinders you, for example streaming protocols use it because you don't need every single packet to be delivered in a live video stream, it's useless if you get a lost packet later
Logged

sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #9 on: September 21, 2009, 10:01:07 PM »

just asking, how do i make the file with the .h file.? i just cant make a folder and add in the .h file and the .c file and ask it to make can i?
Logged
gibbocool
Embellished by our ignorance
News Posters
Hero Member
*

Karma: +34/-11
Offline Offline

Posts: 822
2973.87 points

View Inventory
Send Money to gibbocool

Power Overwhelming


View Profile WWW
« Reply #10 on: September 22, 2009, 03:01:09 AM »

You'll need to add them to your make file.
Logged

jojojoris
Seabears and Fairy tales are real.
C/C++ Developer
Full Member
*

Karma: +15/-4
Offline Offline

Posts: 169
1820.60 points

View Inventory
Send Money to jojojoris

View Profile
« Reply #11 on: September 26, 2009, 04:41:03 AM »

If you want a simple way to connect to an acces point you can use my EasyConnect class.

http://jojosoft.1free.ws/viewtopic.php?f=11&t=8
Logged
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #12 on: September 27, 2009, 06:19:55 PM »

hi! anyone figured a UDP connection yet? lol. for easyconnect, is it under UDP or TCP?
Logged
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
*

Karma: +32/-3
Offline Offline

Posts: 882
2044.69 points

View Inventory
Send Money to AlphaDingDong
Hey... Are you gonna eat that?


View Profile
« Reply #13 on: September 27, 2009, 11:28:51 PM »

Connecting to the AP is a seperate issue from socket transactions. 

Did you read the UDP section in Beej's guide?
Logged
sels
Newbie
*

Karma: +1/-1
Offline Offline

Posts: 23
2057.08 points

View Inventory
Send Money to sels

View Profile
« Reply #14 on: September 30, 2009, 07:59:02 AM »

Dear AlphaDingDong. i tried making my sockets within the PSP, as in, i'm trying to send data and receive the same Data within the psp itself. but theres something not right. can you help me spot my error please?

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define printf pspDebugScreenPrintf
#define SERVERPORT 4950
#define SOL_SOCKET 1
#define SO_BROADCAST 6

PSP_MODULE_INFO("wlan3", 0, 1, 1);
//-----------------------------------------------------------------------------------------------------
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
      //pspSdkInetTerm();
      //   sceNetApctlDisconnect();
      //   sceNetApctlTerm();
         
   sceKernelExitGame();
   return 0;
}
//-----------------------------------------------------------------------------------------------------
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);
   sceKernelSleepThreadCB();

   return 0;
}
//-----------------------------------------------------------------------------------------------------
/* Sets up the callback thread and returns its thread id */
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;
}
//-----------------------------------------------------------------------------------------------------

int fsocket;
int result;
struct sockaddr_in peer;
struct sockaddr_in recvpeer;
int BroadCast = 1;

int CreateSocketSend()
{
  fsocket = sceNetInetSocket(AF_INET, SOCK_DGRAM, 0);// add sceNetInetSocket
  if(fsocket==-1)
  {
    printf("\t\t\terror creating Send socket\n");
    return -1;
  }
  else
  { printf("\t\t\tsocket is Send created\n!");}
  sceNetInetSetsockopt(fsocket, SOL_SOCKET, SO_BROADCAST , &BroadCast, sizeof(BroadCast));
  bzero(&peer, sizeof(peer));
  peer.sin_family = AF_INET;
  peer.sin_port = htons(SERVERPORT);
  peer.sin_addr.s_addr = htonl(INADDR_ANY);

  sceNetInetInetAton("255.255.255.255", &peer.sin_addr);

  result = sceNetInetConnect(fsocket, (struct sockaddr *)&peer, sizeof(peer));//add  sceNetInetConnect
  if(result==-1)
  {
    printf("\t\t\terror connecting Send socket\n");
    return -1;
  }
  else
  { printf("\t\t\tSend socket is connected\n!");}
  return fsocket;
}


int CreateSocketReceive()
{
  /*fsocket = sceNetInetSocket(AF_INET, SOCK_DGRAM, 0);// add sceNetInetSocket
  if(fsocket==-1)
  {
    printf("\t\t\terror creating Receive socket\n");
    return -1;
  }
  else
  { printf("\t\t\tsocket is Receive created\n!");}
  */

  recvpeer.sin_family = AF_INET;
  recvpeer.sin_port = htons(SERVERPORT);
  recvpeer.sin_addr.s_addr = htonl(INADDR_ANY);
  result = sceNetInetBind(fsocket, (struct sockaddr *)&recvpeer, sizeof(recvpeer));//add  sceNetInetConnect
  //sceNetInetBind(int s, const struct sockaddr *my_addr, socklen_t addrlen);

  if(result==-1)
  {
    printf("\t\t\terror binding Receive socket\n");
    return -1;
  }
  else
  { printf("\t\t\tReceive socket is binded\n!");}

  return fsocket;
}
 

int UDPSend()
{
  char *string = "This is a test";
  //char string[] = "this is a test";
  //printf("\t%s\n", *string);

  int SendResult = 0;
  SendResult = sceNetInetSendto(fsocket, string, strlen(string) , 0, (struct sockaddr *)&peer, sizeof(peer));
  //if(SendResult == strlen(string))
  if(SendResult < 0 )
  {
    printf("\n\n\t%d Successfully sent\n\n", string);
    return 1;
  }
  else{printf("\n\n\t%d %d Unsuccessfully sent\n\n",SendResult, strlen(string));return -1;}
 
   //return SendResult == strlen(string);
  //close(fsocket);
  //return (SendResult == sizeof(*string));
}
int UDPReceive()
{
  //while(1)
  //{
    char FUDPData[15];
    //socklen_t SocketLength = sizeof(recvpeer);
    int ReceiveResult = sceNetInetRecvfrom(fsocket, FUDPData, sizeof(FUDPData), 0, (struct sockaddr*)&recvpeer, sizeof(recvpeer));
    if (ReceiveResult == sizeof(FUDPData) )
    {
        printf("\t\t%d Data is received!\n\n", ReceiveResult);
        return 1;
    }
    else
    {
        printf("\t\tData is not received!\n\n");
   return -1;
    }
    /*if(ReceiveResult > 0)
    {
      printf("Receive Error");
    }
    else
    {
      printf("\t\t%s\n\n", FUDPData);
    }*/
    /*if (ReceiveResult > 0)
    {
      printf("Caught message from %s:%d (%d ReceiveResult)\n", FUDPData);
    }*/
    /*if (ReceiveResult > 0)
    {
   printf("Caught message from %s:%d (%d ReceiveResult)\n", inet_ntoa(recvpeer.sin_addr), ntohs(recvpeer.sin_port), ReceiveResult);
    }*/
    //FUDPData[ReceiveResult] = '\0';
    //return 1;
  //}
}
 



int main()
{
  pspDebugScreenInit();
  SetupCallbacks();
 
  if (CreateSocketSend()==-1)
  {
    printf("\n\n\t\tSend Socket failed to make!   \n\n");
  }
  else
  {
    printf("\n\n\t\tSend Socket has been made!   \n\n");
  }
  if(UDPSend()==-1)
  {
    printf("\t\tUDPSend Error. Please Try again.\n");
  }
  else
  {
    printf("\t\tUDPSend() is working!\n\n");
  }
  if (CreateSocketReceive()==-1)
  {
    printf("\n\n\t\tReceive Socket failed to make!   \n\n");
  }
  else
  {
    printf("\n\n\t\tReceive Socket has been made!   \n\n");
  }
  if(UDPReceive()==-1)
  {
    printf("\t\tReceive Error. Please Try again.\n");
  }
  else
  {
    printf("\t\tData has been received!\n\n");
  }
  sceKernelSleepThread();
}
Logged
Pages: [1] 2
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.281 seconds with 38 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com