Register | Login
Forum Index > Samples > Simple Winsock Message Server
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[8] Simple Winsock Message Server - posted: 2011-05-05 16:34:18
This small sample console application acts as a simple message server, if you connect to port 1111 with telnet you will receive the message "Hello World!" and then be disconnected. Very simple, useful to play around with.

Code:
program WIN32CUI 'Sample';

#include 'ziron32.zir';
#include 'smm32.zir';

#include 'kernel32.zir';
#include 'user32.zir';
#include 'messages.zir';

#include 'wsock32.zir';
#include 'console.zir';


const DEFAULT_PORT = 1111;

WSADATA ws;
WSOCKET listensocket;
WSOCKET clientsocket;
sockaddr_in addrinfo;

EAX = WSAStartup(WSOCKVER2_2, @ws);
listensocket = socket(PF_INET, SOCK_STREAM, 0);
addrinfo.sin_family = AF_INET;
addrinfo.sin_addr = INADDR_ANY;
addrinfo.sin_port = htons(DEFAULT_PORT);
bind(listensocket, @addrinfo, sizeof sockaddr_in);
    

listen(listensocket, 20);
while () {
  clientsocket = accept(listensocket, nil, nil);  
  send(clientsocket, 'Hello World!', 12, 0);
  closesocket(clientsocket);
}

//console will never get here. but just in case.
ExitProcess(0); 


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 6 user(s) online. 0 member(s) and 6 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd