[Java for Android App Development] LucaDFA:
Hi everyone, I study electronic and for my project I have to develop an Android-application.

I will explain my project briefly:

Devices:

MSP430FF5529 (debug interface)

CC3100BOOSTERPACK (enable Wi-Fi connection)

HTC one M9

As the title suggest, I have to create a connection between the android device and the MSP430/CC3100.

The program of the MSP430 is an SDK-example of Texas Instrument and it should work, using the Wi-Fi direct on my phone, I see the device and I connect to it.

My problem is that need to exchange files between those devices. However, to do it I need some knowledge of Wi-Fi direct. I want to connect to the CC3100 as client and not as group owner, I know the device IP and the port I should connect to. After the connection is established, the program of the device enter on this function: the input is the number of port.

/*!
\brief Opening a server side socket and receiving data

This function opens a TCP socket in Listen mode and waits for an incoming
TCP connection. If a socket connection is established then the function
will try to read 1000 TCP packets from the connected client.

\param[in] port number on which the server will be listening on

\return 0 on success, -1 on Error.

\note This function will wait for an incoming connection till one
is established

\warning
*/
static _i32 BsdTcpServer(_u16 Port)
{
SlSockAddrIn_t Addr;
SlSockAddrIn_t LocalAddr;

_u16 idx = 0;
_u16 AddrSize = 0;
_i16 SockID = 0;
_i32 Status = 0;
_i16 newSockID = 0;
_u16 LoopCount = 0;
_u16 recvSize = 0;

for (idx=0 ; idx<BUF_SIZE ; idx++)
{
uBuf.BsdBuf[idx] = (_u8)(idx % 10);
}

LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons((_u16)Port);
LocalAddr.sin_addr.s_addr = 0;

SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( SockID < 0 )
{
CLI_Write(" [TCP Server] Create socket Error \n\r");
ASSERT_ON_ERROR(SockID);
}

AddrSize = sizeof(SlSockAddrIn_t);
Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
if( Status < 0 )
{
sl_Close(SockID);
CLI_Write(" [TCP Server] Socket address assignment Error \n\r");
ASSERT_ON_ERROR(Status);
}

Status = sl_Listen(SockID, 0);
if( Status < 0 )
{
sl_Close(SockID);
CLI_Write(" [TCP Server] Listen Error \n\r");
ASSERT_ON_ERROR(Status);
}

newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,
(SlSocklen_t*)&AddrSize);
if( newSockID < 0 )
{
sl_Close(SockID);
CLI_Write(" [TCP Server] Accept connection Error \n\r");
ASSERT_ON_ERROR(newSockID);
}

while (LoopCount < NO_OF_PACKETS)
{
recvSize = BUF_SIZE;

do
{
Status = sl_Recv(newSockID, &uBuf.BsdBuf[BUF_SIZE - recvSize], recvSize, 0);
if( Status <= 0 )
{
sl_Close(newSockID);
sl_Close(SockID);
CLI_Write(" [TCP Server] Data recv Error \n\r");
ASSERT_ON_ERROR(TCP_RECV_ERROR);
}

recvSize -= Status;

}while(recvSize > 0);

LoopCount++;
}

Status = sl_Close(newSockID);
ASSERT_ON_ERROR(Status);

Status = sl_Close(SockID);
ASSERT_ON_ERROR(Status);
CLI_Write(" return function \n\r");
return SUCCESS;
}

I went through p2p guide of "Developer Android" but it is hard without any experience on it.

Can you please help me understand? A button that send a byte would be enough, without any interfaces. Then I should be able to do it on my way.

I downloaded some guides but no one helps on this subject, and of course I searched on this forum an answer but I did not find it.

Thank you for your help

Luca