ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I recognise the namespace is this http://code.google.com/p/sckt/ ?
What type of socket is it UDP or TCP? what is the value of C? is it 0?
Why are you copying the data and not just sending it like so
If it is a problem with the library you can contact the author via the google project page or on <a href="http://www.gamedev.net/community/forums/profile.asp?mode=display&id=99059">gamedev.net</a>
I am using the TCP socket. I think it is not the problem with the library since I only use the sckt function from the site that u mention ( but the file that I found is sckt-0.4), and I have add a few code to suit my program.
Actually I thought that we have to use the variable to send a data, so my intention is to replace the var data with my value.
The c value is an integer which > 0.
Anyway, I have try the code that you have suggested, but i get this error
error: invalid conversion from ‘const char*’ to ‘const sckt::byte*’
error: initializing argument 1 of ‘sckt::uint sckt::TCPSocket::Send(const sckt::byte*, sckt::uint)’
I am using the TCP socket. I think it is not the problem with the library since I only use the sckt function from the site that u mention ( but the file that I found is sckt-0.4), and I have add a few code to suit my program.
Actually I thought that we have to use the variable to send a data, so my intention is to replace the var data with my value.
The c value is an integer which > 0.
Anyway, I have try the code that you have suggested, but i get this error
error: invalid conversion from ‘const char*’ to ‘const sckt::byte*’
error: initializing argument 1 of ‘sckt::uint sckt::TCPSocket::Send(const sckt::byte*, sckt::uint)’
P.S. You should read the sckt.hpp file so that you further understand how the sckt::byte and sckt::uint are defined. I'm not quite sure I understand why the author of the sckt library thought this was important to define (as opposed to using standard system types), but nevertheless he did.
This code is correct, however it *may* only work for short messages. When using TCP sockets, the delivery of the message is guaranteed... however not necessary in one packet!
Thus you will need to insert your Recv() method in a loop to continue receiving data until a condition has been met (i.e. a complete message has been received). Pay careful attention to the return value of Recv() so that you can use it to adjust the insert position within your buf array.
I have not compiled the following, so think of it as "pseudocode":
PHP Code:
sckt::byte buf[1024];
// assume messages are newline terminated sckt::uint bytesReceived = 0;
P.S. If you are developing for Linux-only, feel free to consider using the TCP/UDP Socket library I developed (it is very similar to the sckt library you are currently using). It is located here.
Last edited by dwhitney67; 11-27-2008 at 06:08 AM.
"that means even we do the for loops, the sock.send only run once then it will terminate?"
Is the socket set to non blocking and when you say the above does the application end due to an exception or are you just referring to the loop exiting? Try wrapping the code in a try/catch block.
Actually my program have been run well using this code on client side
Code:
int a = 4;
cout<<"List1:"<<endl;
for (int b=a; b>0; b--)
{
sock.Recv(buf, sizeof(buf));
cout << buf <<endl;
}*/
though i think it is not a good code because im defining the value for looping.
And I think that your suggested code is very efficient and I want to use that code.BUt, it have errors.hope that you can help me.
anywaY, I already get the page that you suggested, but can't open it,
The requested URL /SocketLibrary-1.05.tgz was not found on this server.
Thank you
It would seem that you need to cast the buf to a const char* in the strchr() function.
Quote:
Originally Posted by tqa
anywaY, I already get the page that you suggested, but can't open it,
The requested URL /SocketLibrary-1.05.tgz was not found on this server.
Thank you
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.