Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Error in Web Package example... for sockets
Error in Web Package example... for sockets [message #34765] |
Sun, 11 December 2011 21:04  |
Wolfgang
Messages: 146 Registered: November 2011 Location: Germany
|
Experienced Member |
|
|
In
the first example:
Socket my_sock;
int port=2000;
String host = "192.168.1.2";
if( ClientSocket(my_sock, port, host) );
{
my_sock.Write("hello world!");
my_sock.Close();
}
I think the ; behind
if( ClientSocket(my_sock, port, host) );
is to much and I think you have to give host as second argument and port as third.
if( ClientSocket(my_sock, host, port) )
[Updated on: Mon, 12 December 2011 12:47] Report message to a moderator
|
|
|
Re: Error in Web Package example... for sockets [message #34986 is a reply to message #34765] |
Sat, 24 December 2011 03:15  |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
I think you are right that the ; should be removed and the IP is necessary.
Try one of the working examples.
I added a few things to one of mine:
bool IO;
String snd(String r, int a){
Socket s;
if(!ClientSocket(s, "127.0.0.1", 5024)) {
return "x";
}
if(IO) s.Write(r + "\n\0");
if(a==1 && IO){
String st = s.ReadUntil('\n');
return st;
}
return "y";
}
#endif
The bool IO can be checked or set. If there is no connection time is not wasted for a response, ie: just return "x" and if{...} accordingly.
If a==1 then a response is expected from the server otherwise "y" is returned, otherwise the server will waste time.
Also remember '\n' is the end. If you want to send several lines of data at once replace the '\n' between lines with another delimiter, then as above I use "\n\0" at the end.
More time is usually spent in error handling of possible errors and optimizing rather just writing code that will work (some of the time).
edit: I have made several very dumb mistakes but posting the code and the problem usually someone on the forum will pick up on it and respond, that has been a great help for my errors.
[Updated on: Sat, 24 December 2011 03:54] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue May 13 08:13:40 CEST 2025
Total time taken to generate the page: 0.03298 seconds
|