#
# This is a sample application from TclUDP.
#
-# This illustrates the use of multicast UDP messages to implement a primitive chat
-# application.
+# This illustrates the use of multicast UDP messages to implement a
+# primitive chat application.
#
# $Id$
scrollbar .s -command {.t yview}
frame .f -border 0
entry .f.e -textvariable ::_msg
- button .f.ok -text Send -underline 0 -command "SendMessage $socket \$::_msg"
+ button .f.ok -text Send -underline 0 \
+ -command "SendMessage $socket \$::_msg"
button .f.ex -text Exit -underline 1 -command {destroy .}
pack .f.ex .f.ok -side right
pack .f.e -side left -expand 1 -fill x
grid rowconfigure . 0 -weight 1
bind .f.e <Return> {.f.ok invoke}
.t tag configure CLNT -foreground red
+ .t configure -tabs {90}
}
proc SendMessage {sock msg} {
set msg [string map [list "\r\n" "" "\r" "" "\n" ""] $msg]
set client [lindex $client 0]
if {[string length $msg] > 0} {
- .t insert end "$client " CLNT "$msg\n" MSG
+ .t insert end "$client\t" CLNT "$msg\n" MSG
+ .t see end
}
}
-if {!$tcl_interactive} {
+proc Main {} {
+ variable Address
+ variable Port
+ variable sock
set sock [Start $Address $Port]
CreateGui $sock
- after idle [list SendMessage $sock "$::tcl_platform(user)@[info hostname] connected"]
+ after idle [list SendMessage $sock \
+ "$::tcl_platform(user)@[info hostname] connected"]
tkwait window .
close $sock
+}
+
+if {!$tcl_interactive} {
+ set r [catch [linsert $argv 0 Main] err]
+ if {$r} {puts $::errorInfo} else {puts $err}
exit 0
}
/* set each socket for select */
for (statePtr = sockList; statePtr != NULL; statePtr=statePtr->next) {
- FD_SET(statePtr->sock, &readfds);
+ FD_SET((unsigned int)statePtr->sock, &readfds);
UDPTRACE("SET sock %d\n", statePtr->sock);
}
mreq.imr_interface.s_addr = INADDR_ANY;
if (setsockopt(statePtr->sock, IPPROTO_IP, action,
(const char*)&mreq, sizeof(mreq)) < 0) {
- Tcl_SetObjResult(interp, ErrorToObj("error changing multicast group"));
+ Tcl_SetObjResult(interp, ErrorToObj("error changing multicast group"));
return TCL_ERROR;
}
dlllflags = $(lflags) -dll
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows
-baselibs = $(TCLSTUBLIB) wsock32.lib
+baselibs = $(TCLSTUBLIB) ws2_32.lib
#---------------------------------------------------------------------
# TclTest flags