Project

General

Profile

Want to connect to an client ip and open a text file...

Added by Aake Lind almost 7 years ago

How dos it work?

Here is a example of what i have done!

// create socket

int sock = socket(AF_INET, SOCK_STREAM, 0);

// create traget socket adress

sockaddr_in addr;

addr.sin_port = htons(22);

addr.sin_addr.s_addr = inet_addr("192.168.96.1");

addr.sin_family = AF_INET;

//connect with servers socket

int res = connect(sock,(sockaddr *) &addr, sizeof(addr));

if (res== --1)

{

exit(1);

}

This dosent work.

How do i get it to work with Wt?


Replies (3)

RE: Want to connect to an client ip and open a text file... - Added by Wim Dumon almost 7 years ago

Port 22 = ssh? Writing everything from scratch? I can only try to imagine what the rest of this code will look like when you're finished :-)

I recommend to use some SSH library.

BR,

wim.

RE: Want to connect to an client ip and open a text file... - Added by Aake Lind almost 7 years ago

Hi Vim.

This was just an example of what i want to do in Wt. I need someone to talk idees with. I have written a template in Wt but now i want to connet to an ip adress and get a connection. I dont know how to start this, How to write it in wt.

Best regards Aake.

RE: Want to connect to an client ip and open a text file... - Added by Wim Dumon almost 7 years ago

Aake,

Wt doesn't impose any particular method. Using the plain posix/bsd socket API as you suggest, can be done. But many C or C libraries encapsulate this in various ways to make it easier/more portable/... to use. Your code fragment is too short to see what may be wrong, and there are better fora to ask questions related to socket programming.

Wt, for example, uses boost.asio for all networking needs. In wt/src/Wt/Http/Client.C, you see an implementation of a HTTP client using boost.asio.

Wim.

    (1-3/3)