Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
/* Live Server on port 8888 */ #define _WINSOCK_DEPRECATED_NO_WARNINGS #include<io.h> #include<stdio.h> #include<winsock2.h> #pragma comment(lib,"ws2_32.lib") //Winsock Library #define IP "127.0.0.1" #define PORT 8888 //The port on which to listen for incoming data int main() { SOCKET s; struct sockaddr_in serverSocket, clientSocket; char receiveBuffer[1000]; int clientSocketLength; int recv_len; clientSocketLength = sizeof(clientSocket); WSADATA wsa; //Initialise winsock printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { printf("Failed. Error Code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } printf("Socket Initialised.\n"); //Create a socket if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) { printf("Could not create socket : %d", WSAGetLastError()); } printf("Socket created.\n"); //Prepare the sockaddr_in structure serverSocket.sin_family = AF_INET; serverSocket.sin_port = htons(PORT); serverSocket.sin_addr.s_addr = inet_addr(IP); //serverSocket.sin_addr.s_addr = INADDR_ANY; //Bind if (bind(s, (struct sockaddr*)&serverSocket, sizeof(serverSocket)) == SOCKET_ERROR) { printf("\nBind failed with error code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } printf("Bind done\n\n"); //keep listening for data while (1) { printf("\n\t\t\tWaiting for data...\n"); fflush(stdout); //receiveBuffer[2000]=NULL; if ((recv_len = recvfrom(s, receiveBuffer, 1000, 0, (struct sockaddr*)&clientSocket, &clientSocketLength)) == SOCKET_ERROR) { printf("\n\nrecvfrom() failed with error code : %d", WSAGetLastError()); //exit(EXIT_FAILURE); while (1); } //print details of the client/peer and the data received printf("\n\nReceived packet from %s:%d\n", inet_ntoa(clientSocket.sin_addr), ntohs(clientSocket.sin_port)); printf("\nClient Says: "); printf(receiveBuffer, recv_len); //now reply the client with the same data if (sendto(s, receiveBuffer, recv_len, 0, (struct sockaddr*)&clientSocket, clientSocketLength) == SOCKET_ERROR) { printf("\nsendto() failed with error code : %d", WSAGetLastError()); // exit(EXIT_FAILURE); while (1); } else printf("\nMessage Sent Back to Client"); } closesocket(s); WSACleanup(); return 0; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत