The new via epia pico-itx board is comming, or is it allready here?
Anyway, i have sort of a plan with this board, which i wont explain in all its glory
The question at hand is:
How much code would it take to turn this board in to a network storage device?
The plan is really to make two states of "on" avalible, one just working as a network storage, an the other working as (its a secret).
Anyway, i know close to nothing about network programming, so i though for starters it would be good to get some input on what is required, like tcp/ip and stuff.
Oh ya, of course it wont be running anything like linux or windows, that wouldnt be fun would it?
How much code would it take...
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
I do not think you mean a device since I assume that word would generally refer to something physical although I assume you could describe that the electrical charges are the device running through the computer circuitry and only those charges relevant to this software is the actual device.
Never the less we already have a network storage device in that case? Since we store information that is accessible over a network.
Never the less we already have a network storage device in that case? Since we store information that is accessible over a network.
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
Well. You might do something like this:
Open a UDP port on the server side.
Wait for packets.
Have four major commands for storage access use a header in the UDP packet such as:
Where if:
(opcode = 1) // OPEN
(opcode = 2) //CLOSE
(opcode = 3) // GET
(opcode = 4) // PUT
Then have a format for each opcode such that for OPEN:
The basic idea is to have:
CLIENT -> SERVER -> CLIENT
OPEN -> ... -> RESULT
CLOSE -> ... -> RESULT
READ -> ... -> RESULT
WRITE -> ... -> RESULT
Then keep reusing that NetStorageHdr so that you have a base in which to determine what type of packet something is. The client will need to implement a blocking until it gets a result packet.
// the client sends a packet with ...
send(socketDescriptor, buffer, bufferLength, 0);
// waits for the result ..
recvLen = recv(socketDescriptor, buffer, bufferMaxLength, 0);
// hands result back to core function
The OPEN and CLOSE help with:
If you are working on linux you can at a console type:
man socket
This should get you started in the right direction to using sockets.
Open a UDP port on the server side.
Wait for packets.
Have four major commands for storage access use a header in the UDP packet such as:
Code: Select all
struct tNetStorageHdr
{
uint8_t opcode;
};
(opcode = 1) // OPEN
(opcode = 2) //CLOSE
(opcode = 3) // GET
(opcode = 4) // PUT
Then have a format for each opcode such that for OPEN:
Code: Select all
struct tNetStorageDataHdr
{
uint32_t fileHandle;
uint32_t filePos;
uint32_t length;
};
void GotPacket(void *data)
{
struct tNetStorageHdr *hdr = (struct tNetStorageHdr*)data;
switch(hdr->opcode)
{
case 1:
mode = *((uint32_t*)&hdr[1]);
filename = *((uint8_t*)( ((uintptr_t)&hdr[1]) + sizeof(uint32_t) );
// make sure it is okay to open it if someone else already has it opened.
// make entry who opened this file.
// send back packet with fileHandle
break;
case 2:
fileHandle = *((uint32_t*)&hdr[1]);
// close file with handle
break;
case 3:
struct tNetStorageDataHdr *dhdr = (struct tNetStorageDataHdr*)&hdr[1];
/// check if file handle is opened
/// read data specified
/// send packet back with data
break;
case 3:
/// same as READ, but in reverse.
}
}
The basic idea is to have:
CLIENT -> SERVER -> CLIENT
OPEN -> ... -> RESULT
CLOSE -> ... -> RESULT
READ -> ... -> RESULT
WRITE -> ... -> RESULT
Then keep reusing that NetStorageHdr so that you have a base in which to determine what type of packet something is. The client will need to implement a blocking until it gets a result packet.
// the client sends a packet with ...
send(socketDescriptor, buffer, bufferLength, 0);
// waits for the result ..
recvLen = recv(socketDescriptor, buffer, bufferMaxLength, 0);
// hands result back to core function
The OPEN and CLOSE help with:
- Access Control
- Earlier Error Control
- Increased Network And CPU Performance
If you are working on linux you can at a console type:
man socket
This should get you started in the right direction to using sockets.