The goahead WebServer is being transplanted. You can see an article transplanted on VxWorks.

Source: Internet
Author: User
Tags socket error htons
I have done Web cgi programs on vswitches in the past. It was done on the 51 system. I remember that the Principles are similar. I made the pages into binary arrays, But now I forgot, I had to get familiar with it again. The following are from http://ajonbin.spaces.live.com/blog/cns! 5619a73390dcd51e! 132. Entry. If you have any copyright issues, please let me know.

Goahead, VxWorks, and CGI are the most closely-monitored clients in VxWorks. Basically, you can use the previous IPTV code to change it. That's OK. However, there is a big problem. IPTV has an interface and is controlled through a remote control. After all, using remote control is still troublesome. If you input text again, it will be even more frustrating. It is very easy to monitor the client. Do not use complicated interfaces. Therefore, you should consider embedding a web server in the client. All operations and configurations are performed on the webpage, which is a good choice. Http://www.goahead.com) East good ah, support multi-platform. Like this. Load a version 2.1.8, compile it on the window, run, access, everything is OK. Start porting to VxWorks. It has a VxWorks makefile. Just change it. Cc = ECC.
Link = ELD
AR = arcflags + =-dwebs_page_rom-dwebs-duemf-dos = "VxWorks"-dvxworks $ (umsw) $ (dasw)-wall $ (sslsw)-I $ (rtos_effecdes) -I .. /Add COMP:
ECC-I ../-I./-O webcomp $ (cflags) ../webcomp. c
Find.../Web-name "*. *"> the macro websfile-dwebs_page_rom must be added. Goahead can package web files into an array of C languages, which is suitable for embedded systems without hard disks. Let's talk about how to package web files. The built-in web directory is used as an example. In. in the/win/directory, there is a webcomp.dswproject. Compile the executable file webcomp.exe and then run webcomp.exe .. /Web websfile> webrom. in C, websfile is found in makefile .. /Web-name "*. * "> generated by websfile, that is, the file list in the web page Directory ,.. /web is the file prefix in the file list. You can see websfile. Webrom. c is the generated webpage data file. Then, replace webrom. C with the original webrom. C and remove the input parameter from the webmain function in./vxwokrs. Modify the web root directory main. c: l 172 sprintf (webdir, "% S/% s", root_dir, rootweb); changed to sprintf (webdir ,". /"); // This is the conclusion of repeated experiments. We have worked hard to compile webs and generate libwebs. A then add taskspawn ("websvxmain", 1024, 100 *, websvxmain, 0, 0, 0, 0, 0, 0, 0, 0) to the client; ie accesses one, OK. WebServer is running, but the communication between webserver and client programs is a big problem! I have asked a lot of people, searched several times, and there is no good way. I was wondering if webserver could directly call the C function. This seems difficult. Finally, we decided to use the CGI program and socket to communicate with the web server in the video client. It is to create a socket in the CGI program and communicate with the vidoe client. It took a lot of time to complete the experiment in windows and started writing socket. The Code is as follows: HTML page: <HTML>
<Form action = "/cgi-bin/multi.exe" method = get>
<P> input data structure <input name = "M" size = "5">
<Input name = "N" size = "5"> <br>
<Input type = "Submit" value = "OK">
</Form>
</Html> CGI program int main (void)
{
Char * data;
Long M, N;
Int I = 0; // generate a form
Printf ("% S % C", "Content-Type: text/html; charset = gb2312", 13, 10 );
Printf ("<HTML> ");
Printf ("<title> multiplication result </title>/N ");
Printf ("Data = getenv ("QUERY_STRING ");
If (Data = NULL)
{
Printf ("<p> error! Data is not input or there is a problem with data transmission/N ");
}
Else if (sscanf (data, "m = % LD & n = % lD", & M, & N )! = 2)
{
Printf ("<p> error! The input data is invalid. The number must be entered in the form. /N ");
}
Else
{
Printf ("<p> % LD and % ld: % lD. /N ", m, n, m * n );
} // Send data
{
Word wversionrequested;
Wsadata;
Int err;
Socket s_send;
Struct sockaddr_in localaddr;
Struct sockaddr_in peer_addr;
Char Buf [4] = {0}; wversionrequested = makeword (2, 0 );
Err = wsastartup (wversionrequested, & wsadata );
If (Err! = 0)
{
Printf ("Start Up Error/N ");
Return-1;
}
S_send = socket (af_inet, sock_dgram, ipproto_udp );
If (s_send =-1)
{
Int I = getlasterror ();
Printf ("create error % d/N", I );
Return-1;
}
Printf ("s_send = % d/N", s_send );
Memset (& localaddr, 0, sizeof (struct sockaddr_in ));
Localaddr. sin_family = af_inet;
Localaddr. sin_port = htons (1600 );
Localaddr. sin_addr.s_addr = htonl (inaddr_any );
If (BIND (s_send, (struct sockaddr *) & localaddr, sizeof (struct sockaddr_in) =-1)
{
Printf ("BIND error % d/N", getlasterror (); Return-1;
}

Memset (& peer_addr, 0, sizeof (struct sockaddr_in ));
Peer_addr.sin_family = af_inet;
Peer_addr.sin_port = htons (0, 11000 );
Peer_addr.sin_addr.s_addr = inet_addr ("172.16.66.85"); sendto (s_send, Buf, 4,0, (struct sockaddr *) & peer_addr, sizeof (peer_addr ));
Printf ("Send/N"); closesocket (s_send );
}
Printf ("} Compile and generate multi.exe in the CGI-BIN directory. Structure found that a create socket error occurs. The error code is 10106. the requested service provider cannot be loaded or initialized. Oh, God! We haven't encountered any problems yet. Continue to Google, and get some prompts, as if the environment variable is not set with the _ putenv ("systemroot = C: // windows ");
Ah, perfect! Work continues... there are still many problems. I don't know what problems will happen in VxWorks. I wish you good luck.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.