|
|
Home » Developing U++ » U++ Developers corner » Help needed with link errors (serversocket)
Help needed with link errors (serversocket) [message #48510] |
Tue, 11 July 2017 23:46  |
imos
Messages: 17 Registered: July 2017
|
Promising Member |
|
|
Hi
I am trying to find a dev env to develop a socket oriented deamon (non-blocking) using high level approachs (for sockets and data structures) and I decided to give a try to U++.
I am trying to put to work the ServerSocket example but I have link errors that I can not solve alone. Here the code:
#include <Core/Core.h>
#include <Web/Web.h>
using namespace Upp;
Socket accept_socket, data_socket;
int port = 2020;
CONSOLE_APP_MAIN
{
if(!ServerSocket(accept_socket, port)) // Listen for connections using _accept_socket;
{
throw Exc("Couldn't bind socket on the local port.");
}
// You can do this in a loop to accept many connections:
if( accept_socket.IsOpen() )
{
dword ip_addr;
// Hand off successful connection to _data_socket
if( !accept_socket.IsError() && accept_socket.Accept(data_socket, &ip_addr) )
{
//Cout() << "Connection from " << FormatIP(m_ipaddr) << "\n";
Cout() << "Connection from " << "\n";
// Read from the socket until it is closed, has an error, or you see an end-of-file marker
// (EOF optional and application-specific)
while(data_socket.IsOpen() && !data_socket.IsEof() && !data_socket.IsError())
{
Cout() << data_socket.Read();
}
}
Cout() << "\n";
}
}
I also added the Web package to the project but I get these link errors:
...Web/html.cpp (347): error: ambiguous overload for 'operator+' (operand types are 'Upp::HtmlTag' and 'Upp::Htmls')
.../Web/auth.cpp (219): error: ambiguous overload for 'operator+' (operand types are 'Upp::Htmls' and 'Upp::HtmlTag')
Etc.
Thanks a lot
Imos
|
|
|
|
|
|
Re: Help needed with link errors (serversocket) [message #48519 is a reply to message #48518] |
Wed, 12 July 2017 23:08   |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
Hello Imos,
Quote:
Now I am going to try it using non-blocking approach and single thread if possible... Is it possible to use non-blocking socket using the TcpSocket class?
Yes it is possible to use non-blocking socket using the TcpSocket class.
TcpSocket class allows blocking, non-blocking, and time-constrained operations.
You have to set Timeout value to 0 to put TcpSocket in a non-blocking mode.
But I suggest you first reading the TcpSocket api docs before you plunge into the world of non-blocking sockets, and then get yourself familiar with U++ core classes & concepts.
Non-blocking socket operations can easily get tricky and complex.
However, there are ways to reduce complexity.
Below you can find a queue model designed exactly for non-blocking socket operations.
It also contains an example code called ClientSockets, which is actually a non-blocking version of SocketClient example with multiple requests.
But it requires some knowledge of U++ callbacks, and C++11 lambdas.
Should you have any further qustions, I may be able to answer them.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 12 July 2017 23:10] Report message to a moderator
|
|
|
Re: Help needed with link errors (serversocket) [message #48521 is a reply to message #48519] |
Thu, 13 July 2017 10:50  |
imos
Messages: 17 Registered: July 2017
|
Promising Member |
|
|
Thanks Oblivion for your availability for helping...
I am going to try the sample and modify it and find out how Upp handles thousands of sockets handles using just one (or two) thread(s) (which is my main aim)...
Thanks a lot
Imos
|
|
|
Goto Forum:
Current Time: Sun May 11 14:35:14 CEST 2025
Total time taken to generate the page: 0.03359 seconds
|
|
|