我正在阅读Python 2.7.10中的两个带有客户端和服务器的程序.如何修改这些程序以便从客户端向服务器发送消息?
server.py:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection …Run Code Online (Sandbox Code Playgroud) 我想问为什么我有:
int main() {
printf( "Hello world") ;
main ;
}
Run Code Online (Sandbox Code Playgroud)
编译器打印"Hello world",但是当我有main()而不是main时,它会重复打印"Hello world".
我试图用 C 语言理解这种程序,但我不能。确切地说,我无法弄清楚 *s 是如何更改的,以及为什么编译器显示 210012。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void WhatIamDoing(char *s) {
char ch;
if (*s) {
ch = *s;
s++;
WhatIamDoing(s);
putchar(ch);
}
}
int main() {
char s[20] = "012" ;
WhatIamDoing(s) ;
printf( "%s", s ) ;
}
Run Code Online (Sandbox Code Playgroud)