Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,003 Views

sendto?

I'm trying to send some data over ethernet on the DE2-115, not files, just chunks of random data which I can encode into an IPv4 packet and I know I have to use the the sendto command. However I'm having trouble figuring out how to use it from the server example that comes with the DE2-115. I get that it's  

 

sendto(conn->fd, data, pkgLth, 0,(struct sockaddr *)&cliaddr,nLen); 

 

But all variables inside, conn, fd, data, pkgLth, etc... I'm not sure how to define in the context of my code. Any help would be greatly appreciated.
Tags (1)
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
33 Views

If You're trying only to send data, then use either ip_write() or udp_send()

Altera_Forum
Honored Contributor I
33 Views

sendto can be used to send data on udp or tcp sockets. Have a look at those examples (http://en.wikipedia.org/wiki/bsd_socket).

Altera_Forum
Honored Contributor I
33 Views

 

--- Quote Start ---  

#include <stdio.h> 

# include <string.h> 

# include <ctype.h>  

 

/* MicroC/OS-II definitions */ 

# include "includes.h" 

 

/* Simple Socket Server definitions */ 

# include "simple_socket_server.h"  

# include "alt_error_handler.h" 

 

/* Nichestack definitions */ 

# include "ipport.h" 

# include "tcpport.h" 

# define MAXDATASIZE 200 

 

void SSSSimpleSocketServerTask() 

int sockfd, acceptsocket, addrlen; 

struct sockaddr_in server_addr, client_addr; 

addrlen = sizeof(client_addr); 

 

 

if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 

alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Socket creation failed"); 

else 

printf("Socket created"); 

server_addr.sin_family = AF_INET; 

server_addr.sin_port = htons(SSS_PORT); 

server_addr.sin_addr.s_addr = INADDR_ANY; 

memset(&(server_addr.sin_zero), '\0', 8); 

 

if ((bind(sockfd,(struct sockaddr *)&server_addr,sizeof(server_addr))) < 0) 

alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Bind failed"); 

else 

printf("Bind is OK\n"); 

 

if ((listen(sockfd,5)) < 0) 

alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Listen failed"); 

else 

printf("Listen is OK\n"); 

while(1) 

 

if ((acceptsocket = accept(sockfd,(struct sockaddr *)&client_addr,&addrlen)) < 0) 

alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"accept failed"); 

else 

printf("accepted connection request\n"); 

sockfd = acceptsocket; 

break; 

 

int long bytes_sent; 

int long bytes_recv; 

char sendbuf[MAXDATASIZE] = "This is a test string from server"; 

char recvbuf[200] = ""; 

 

printf("Server: Sending some test data to client...\n"); 

bytes_sent = send(sockfd, sendbuf, strlen(sendbuf), 0); 

 

if((bytes_sent = send(acceptsocket,sendbuf,strlen(sendbuf),0)) < 0) 

printf("SERVER : send failed.\n"); 

else 

printf("SERVER : Send is OK \n"); 

printf("SERVER : Bytes sent:%ld.\n",bytes_sent); 

 

if((bytes_recv=recv(acceptsocket,recvbuf,200,0))<0) 

printf("SERVER : receive failed.\n"); 

else 

printf("SERVER: recv() is OK.\n"); 

printf("SERVER: Received data is: \"%s\"\n", recvbuf); 

printf("SERVER: Bytes received: %ld.\n", bytes_recv); 

 

return ; 

 

--- Quote End ---  

 

 

I tried using the code from Wikipedia however it doesn't seem to work. Nios recognizes my board and receives some connection bytes from my PC, however it never sends any data to my PC. I tried changing around the IP address to mine but that always failed. I appreciate your help, any other suggestions? 

 

So to give a bit more back history, I am starting with the web server example that comes with the DE2-115. And all that I'm doing is replacing the code in webs_server.c with the code above or other code I have found. I'm pretty certain by now that's not how I'm supposed to be doing this but I'm not sure how exactly to do it. 

 

Note: The console gives me this and always hangs after that point: 

 

 

--- Quote Start ---  

nios2-terminal: connected to hardware target using JTAG UART on cable 

nios2-terminal: "USB-Blaster [USB-0]", device 1, instance 0 

nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate) 

 

InterNiche Portable TCP/IP, v3.1  

 

Copyright 1996-2008 by InterNiche Technologies. All rights reserved.  

prep_tse_mac 0 

Your Ethernet MAC address is 00:07:ed:ff:6b:c7 

prepped 1 interface, initializing... 

[tse_mac_init] 

INFO : TSE MAC 0 found at address 0x08222000 

INFO : PHY Marvell 88E1111 found at PHY address 0x10 of MAC Group[0] 

INFO : PHY[0.0] - Automatically mapped to tse_mac_device[0] 

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link... 

INFO : PHY[0.0] - Auto-Negotiation PASSED 

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link... 

INFO : PHY[0.0] - Auto-Negotiation PASSED 

--- Quote End ---  

Reply