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

avatar

(send private message)

Posts: 923
Topics: 54

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 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 533, May 5, 2016, 7:19 am.


Statistics:
Threads: 223 | Posts: 1835 | Members: 50 | Active Members: 50
Welcome to our newest member, NobodyAtWork
const Copyright = '2011-2017 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd