<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-15">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
I'm currenting writing a project in which two nodes communicate each
other and the controlling agent sends data to the other one.<br>
I've implementing my communication structure using XMPP and I'm able
to let my nodes communicate.<br>
You can find my project on GitHub: <a
href="https://github.com/marcoxsurf/NiceStrophe/">https://github.com/marcoxsurf/NiceStrophe/</a><br>
Now I have to let the controlling node to share a file to the
controlled one. I have followed this discussion <a
href="http://lists.freedesktop.org/archives/nice/2012-September/000633.html">http://lists.freedesktop.org/archives/nice/2012-September/000633.html</a>
but I have still problems.<br>
Here it is the code that I'm testing:<br>
-----------<br>
/ Connect to the signals<br>
g_signal_connect(agent,
"candidate-gathering-done",G_CALLBACK(cb_candidate_gathering_done),
NULL);<br>
g_signal_connect(agent, "component-state-changed",
G_CALLBACK(cb_component_state_changed), NULL);<br>
if (controlling){<br>
//find out file size<br>
stat("test.txt", &sstr);<br>
sent_byte=0;<br>
total_byte=sstr.st_size;<br>
file = fopen("test.txt", "rb");<br>
g_signal_connect(agent, "reliable-transport-writable",
G_CALLBACK(writable_cb), file);<br>
} else{<br>
file_received = fopen("testFile-received.txt", "ab");<br>
}<br>
-----------<br>
void <br>
cb_nice_recv(NiceAgent * agent, guint stream_id, guint component_id,<br>
guint len, gchar * buf, gpointer user_data) {<br>
if (len == 1 && buf[0] == '\0'){<br>
if (!file_received){<br>
fclose(file_received);<br>
}<br>
g_main_loop_quit (gloop);<br>
return;<br>
}<br>
if (file_received) {<br>
int writen = fwrite(buf, sizeof(char), len, file_received);<br>
printf("RECEIVED FILE: buf size: %d , writen size: %d\n",
len,<br>
writen);<br>
} else {<br>
perror("ERROR OPENING FILE\n");<br>
}<br>
}<br>
<br>
void <br>
writable_cb(NiceAgent *agent, guint sid, guint cid, gpointer data) {<br>
if (!file){<br>
file = data;<br>
}<br>
char *file_chunk = malloc(CHUNK_SIZE);<br>
size_t nbytes = 0;<br>
int sent = 0;<br>
while ((nbytes = fread(file_chunk, sizeof(char), CHUNK_SIZE,
file)) > 0) {<br>
//printf("SENDING: %s\n",file_chunk);<br>
//Returns: The number of bytes sent<br>
sent = nice_agent_send(agent, stream_id,
NICE_COMPONENT_TYPE_RTP,nbytes, file_chunk);<br>
/* If return value is -1 it means nothing was sent */<br>
if (sent==-1)<br>
sent = 0;<br>
sent_byte+=sent;<br>
printf("SENT FILE: chunk size: %zu send result:
%d.\n",nbytes,sent);<br>
if (sent < nbytes) {<br>
<br>
/* seek back to the last byte that was actually sent, so
it gets<br>
read on the next pass */<br>
fseek(file, -(nbytes - sent), SEEK_CUR);<br>
/* break and exit the function, wait for the next signal
callback<br>
to continue sending the rest of the data */<br>
break;<br>
}<br>
<br>
}<br>
if (sent_byte==total_byte){<br>
printf("END");<br>
nice_agent_send(agent, stream_id, 1, 1, "\0");<br>
g_main_loop_quit (gloop);<br>
}<br>
}<br>
<br>
I've tried this code in a local env and it's all working fine with
files of different size. (dd if=/dev/urandom of=test.txt count=1024
ibs=1 ---> 1K)<br>
The problems come when i want to use my code in real life.<br>
I've tried to send:<br>
<ul>
<li>40-byte-size file: OK</li>
<li>1KB-size file: OK</li>
<li>+2KB-size file: problems<br>
</li>
</ul>
<p>Output Controlling node with 2K size:<br>
</p>
<p>waiting for state READY or FAILED signal...SIGNAL: state changed
1 1 connected[3]<br>
SENT FILE: chunk size: 1024 send result: 1024.<br>
SENT FILE: chunk size: 1024 send result: 1024.<br>
</p>
<p>Output controlled node:<br>
</p>
<p>RECEIVED FILE: buf size: 1024 , writen size: 1024<br>
.... hunging up....</p>
<p>What am I missing? Could you help me please?<br>
</p>
<p><br>
</p>
<br>
<br>
</body>
</html>